Skip to main content
Participating Frequently
June 12, 2015
Answered

How to have 2 enter_frame functions happening in the one frame? I have a scene where I have an animated movie moving across the scene and I also want to have a custom cursor also enter the scene on the same frame.

  • June 12, 2015
  • 1 reply
  • 661 views

var mc_Dog1:WagDog = new WagDog();

addChild(mc_Dog1);

//mc_Dog1.x = 50; I have this in my ENTER_FRAME event handler)

mc_Dog1.y = 20;

mc_Dog1.width = 140;

mc_Dog1.height = 120;

addEventListener(Event.ENTER_FRAME, dogMove);

    function dogMove(event:Event):void

{

        if (mc_Dog1.x < (stage.stageWidth+25)) {

        mc_Dog1.x += 2;

        //myCursor.mouseEnabled=false; The commented custom cursor is also a movie clip, I need this format as in my animated quiz I am also using drag and drop)

        //Mouse.hide();

        //myCursor.x = root.mouseX;

   

        //myCursor.y = root.mouseY;

        }else{

        mc_Dog1.x = -25;

                 }

   }

This topic has been closed for replies.
Correct answer kglad

you can use one or two enterframe listeners.  eg,

a) 1 listener

this.addEventListener(Event.ENTER_FRAME,f)

function f(e:Event):void{

f1();

f2();

}

b) 2 listeners

this.addEventListener(Event.ENTER_FRAME,f1);

this.addEventListener(Event.ENTER_FRAME,f2)

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 12, 2015

you can use one or two enterframe listeners.  eg,

a) 1 listener

this.addEventListener(Event.ENTER_FRAME,f)

function f(e:Event):void{

f1();

f2();

}

b) 2 listeners

this.addEventListener(Event.ENTER_FRAME,f1);

this.addEventListener(Event.ENTER_FRAME,f2)

Participating Frequently
June 13, 2015

okay cool I will try this out, thank you for your prompt reply.

I am so near the end of my assignment, just need this and a couple of other things to work and it's finished.

Cheers

Participating Frequently
June 13, 2015

you're welcome.


this.addEventListener(Event.ENTER_FRAME, f);

function f (event:Event):void{        

//TypeError: Error #1009: Cannot access a property or method of a null object reference.

//    at Pet_Intelligence_QuizV15_fla::MainTimeline/f2()

//    at Pet_Intelligence_QuizV15_fla::MainTimeline/f()

/*

at Pet_Intelligence_QuizV15_fla::MainTimeline/frame4()[Pet_Intelligence_QuizV15_fla.MainTimeline::frame4:151]

    at flash.display::MovieClip/gotoAndStop()

    at Pet_Intelligence_QuizV15_fla::MainTimeline/Begin()[Pet_Intelligence_QuizV15_fla.MainTimeline::frame2:42]

Debug session terminated.

*/

    f1();

    f2();

   

    }

   

function f1():void

{

       

   

    if (mc_Dog1.x < (stage.stageWidth+25)) {

        mc_Dog1.x += 2;

       

       

    }else{

            mc_Dog1.x = -25;

    }

           

}

myCursor.mouseEnabled=false;

// hide the real mouse

Mouse.hide();

// show where the function we made when we made our event listener

function f2():void {

   

// make our custom cursor's position equal the real mouse's position

myCursor.x = root.mouseX;

myCursor.y = root.mouseY;

}

I have tired in so many different ways to get these two enter frames to work together on the one frame. somewhere between frame 2, my login screen and frame 4 my question screen.

I have a go to and play from frame two and then the error then stops when my xml is to be loaded, if I don't bother with my custom cursor it works fine, go figure..lol However I need the custom cursor on all frames for a pass at the least.

Have tried even as my lecturer has suggested and that is no better.

Can you see if I have made any fundamental errors in the code above?

Cheers