Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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.

New Here ,
Jun 12, 2015 Jun 12, 2015

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;

                 }

   }

TOPICS
ActionScript
589
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 12, 2015 Jun 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)

Translate
Community Expert ,
Jun 12, 2015 Jun 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 12, 2015 Jun 12, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 12, 2015 Jun 12, 2015

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 13, 2015 Jun 13, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 13, 2015 Jun 13, 2015

if that code is on the main timeline remove the root reference.  otherwise use MovieClip(root)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 13, 2015 Jun 13, 2015

Have tried both  of your suggestions, still not working. Will give it a break and try my lecturer again tomorrow... there is definitely something to do with the one the location and two possible the placing of the code in that frame.

Very interesting problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 15, 2015 Jun 15, 2015

Hello again, I forgot to give my custom cursor an instance name for this frame of myCursor, my bad.

MovieClip(root) makes it work perfectly.

All I need to do now is how the custom cursor be on top of all the objects rather than underneath my drag and drop movie clips.

Is there another step?

Thank you so much for your help this at least gets me a pass for my assignment

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 16, 2015 Jun 16, 2015
LATEST

you're welcome.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines