Sunday 15 August 2010

arguments - animate MovieClip using addEventListener - actionscript 3 -


Actually I can terminate this code, but I'm misunderstood with arguments and removing Avent Alisher I am My first code is:

First Code:

  running public function) {var Bob: Bob = new Bob (); Bob.x = 0; Bob.y = 300; AddChild (Bob); BobRun (); } Personal Function Bobrun () {bob.addEventListener (Event .ENTER_FRAME, AnimBob); } Private function animateBob (event: incident) {if (bob.x & lt; = 200) {bob.x + = 2; Bob.gotoAndPlay (bob.currentFrame); } And {bob.got and Stop (1); Trace ("bob.stop"); Bob.removeEventListener (Event .ENTER_FRAME, AnimBob); }}   

The second code:

  running public function (choose var: boolean = false; bobran (0 , 300, 200, 300);} Personal Function bobRun (startX: number, starting number: endx: number, endway: number) {bob.addEventListener (event.ENTER_FRAME, function (e: event): zero {startx = bob. X; startY = bob.y; If (startX! = EndX || startY! = EndY) {select = true; if (startX  endx; start & lt; endY) {bob.x - = 1; bob.y + = 1;} if (startX == andx & amp; ; Start & gt; And Y) {bob.- = 1;} if (startX == andx & amp; get started & lt; endY) {bob.y + = 1;} if (startX  andx and startY == end y) {bob.x - = 1;} bob.gotoAndPlay (bob.currentFrame);} and {bob.got and stop ( 1); Trace ("Bob .stop");}}}}   

In the first code, I bob.removeEventListener (Event.ENTER_FRAME, animateBob); to delete the listener, and this work is fine, but in the first code I can not use arguments like other code bobrun (startX: number, start: number, andx: Number, endway: number er) . .

In the second code, I get the listener first code like bob.removeEventListener (Event.ENTER_FRAME, animateBob); , so trace ("Bobstop"); Can not stop in the output panel, but I can use arguments.

I need logic and remove EventListener to create my project, please help me guys: '(

For the first snippet of code, you can use the intermediary function if you want bobRun () {bob.addEventListener (Event.ENTER_FRAME, enterFrameEventHandler);} public Function enterFrameEventHandler (e: Event): void {/ p>

atom (arg1, arg2, arg3); // this is where you will pass your arguments}

A You are using an anonymous function for the second snippet of d; Thus, you can just add ...

  e.target.removeEventListener (e.type, arguments.callee );   

... Whatever logic you think is like removing the listener.

No comments:

Post a Comment