dcsimg
A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 26 of 26

Thread: [RESOLVED] Noob trying to learn arrays ...

  1. #21
    Member
    Join Date
    Nov 2007
    Posts
    38
    Quote Originally Posted by deadlock32
    you should only have to setupVars() once.

    But the reason for that error and anytime that you see Expected 0 got 1 means that you have setupVars( ZERO items here ) but the compiler is expecting: setupVars( ONE thing here)

    in your case the compiler is expecting setupVars(evn:Event) from your enterFrame event. any function that is triggered from an event needs to have an Event var defined in the function.

    but mouse event and mouse over will happen any time you mouse hovers over the boxes, so if you make setup vars work on an enterframe, you in tern create a problem of adding event listeners to the objects that already have them.

    something you may even want to consider doing (after you get it to work ; P ) is working with the event listeners in this fashion:
    I swear, I am braindead today. I don't know why I didn't realize that error. Thanks for pointing out my retardation.

    Thanks for the pointers about the listeners as well.

  2. #22
    When the eventListener calls the function setupVars every time it enters a frame it puts into the parameter of that function an Event variable. So to call the setupVars through the use of an event you would have to change the parameters of your function and say that an event will pass into it whenever it is called. Also ENTER_FRAME event will call the function every time it enters that frame which is 30 times a second in your case.

    Here's your code fixed

    Code:
    import fl.transitions.*; 
    import fl.transitions.easing.*;
    
    addEventListener(Event.ENTER_FRAME, setupVars);
    
    function setupVars(e:Event):void {
    	trace("Entering setupVars");
    	//The following removes the Event.ENTER_FRAME listener so that it does not activate 30 times a second.
    	removeEventListener(Event.ENTER_FRAME,setupVars);
     var myArray:Array = [box1_mc, box2_mc];  
     for(var i:Number = 0; i < myArray.length; i++) {
        myArray[i].addEventListener(MouseEvent.MOUSE_OVER, boxOver);
        myArray[i].addEventListener(MouseEvent.MOUSE_OUT, boxOut);
    	myArray[i].buttonMode = true;
       }
    }
    var box:Tween;
    var box2: Tween;
    function boxOver(ev:Event):void {
    	 box = new Tween(ev, "width", Elastic.easeIn, 100, 130, .5, true);
    	 box = new Tween(ev, "height", Elastic.easeIn, 100, 130, .5, true)
    	 trace("yay, it works")
    }
    
    function boxOut(ev:Event):void {
    	 box2 = new Tween(ev, "width", Elastic.easeOut, 130, 100, .5, true);
    	 box2 = new Tween(ev, "height", Elastic.easeOut, 130, 100, .5, true);
    	 trace("yay, this one works, too")
    }
    Posted a bit late, but it may help.

  3. #23
    Member
    Join Date
    Nov 2007
    Posts
    38
    Ah ha! Almost there!
    Good call on removing the ENTER_FRAME. I actually had that problem in another thing I was working on last week and forgot the removal there, too. Guess this'll help me remember that in the future.

    Now, the only thing not working is the tween:
    ReferenceError: Error #1056: Cannot create property width on flash.events.MouseEvent.

    I don't quite understand that, however. I've included tweens inside functions before, and never saw that. Hmm.

  4. #24
    When your use ev when creating the tween your using an event variable which is not a DisplayObject. But a property of the event variable is the target, or the thing that called the event. So you would use ev.target, which is the Movieclips on your scene.

    This code works:

    Code:
    import fl.transitions.*; 
    import fl.transitions.easing.*;
    
    addEventListener(Event.ENTER_FRAME, setupVars);
    
    function setupVars(e:Event):void {
    	trace("Entering setupVars");
    	//The following removes the Event.ENTER_FRAME listener so that it does not activate 30 times a second.
    	removeEventListener(Event.ENTER_FRAME,setupVars);
     var myArray:Array = [box1_mc, box2_mc];  
     for(var i:Number = 0; i < myArray.length; i++) {
        myArray[i].addEventListener(MouseEvent.MOUSE_OVER, boxOver);
        myArray[i].addEventListener(MouseEvent.MOUSE_OUT, boxOut);
    	myArray[i].buttonMode = true;
       }
    }
    var box:Tween;
    var box2: Tween;
    function boxOver(ev:Event):void {
    	 box = new Tween(ev.target, "width", Elastic.easeIn, 100, 130, .5, true);
    	 box = new Tween(ev.target, "height", Elastic.easeIn, 100, 130, .5, true)
    	 trace("yay, it works")
    }
    
    function boxOut(ev:Event):void {
    	 box2 = new Tween(ev.target, "width", Elastic.easeOut, 130, 100, .5, true);
    	 box2 = new Tween(ev.target, "height", Elastic.easeOut, 130, 100, .5, true);
    	 trace("yay, this one works, too")
    }
    Looks neat too

  5. #25
    a.k.a gltovar deadlock32's Avatar
    Join Date
    May 2001
    Location
    Naperville,IL
    Posts
    489
    Quote Originally Posted by buttbutt
    Ah ha! Almost there!
    Good call on removing the ENTER_FRAME. I actually had that problem in another thing I was working on last week and forgot the removal there, too. Guess this'll help me remember that in the future.

    Now, the only thing not working is the tween:
    ReferenceError: Error #1056: Cannot create property width on flash.events.MouseEvent.

    I don't quite understand that, however. I've included tweens inside functions before, and never saw that. Hmm.

    ahh but you forget, ev:Event. ev is Event. ev.currentTarget is displayObject.

    ev.width == null/undefined
    ev.currentTarget.width == targeted width.

    remember when adding an event listener to something, the ev:Event is the event itself. on of the properties of ev is ev.currentTarget which refers to the item that you added the event to, in this case it looks like it could be a movieClip.

  6. #26
    Member
    Join Date
    Nov 2007
    Posts
    38
    Of course! It works!
    Thanks so much guys!

    Now to play with arrays more. Expect lots more threads from me. lol

    Oh, and how do I mark this resolved? I can't edit my first post anymore.
    Last edited by buttbutt; 11-20-2007 at 12:22 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center