Skip to main content
November 28, 2014
Question

About current frame property

  • November 28, 2014
  • 1 reply
  • 1757 views

Hello I am trying to make as3 take action when a certain frame is reached. As far as I understand I need to use current frame property. But it does not work for some reason. It is about as. file so my object is referred to as "this". 

if (this.hitTestObject(_root.mcBall)){

    _root.ballYSpeed *= -1

    if(!hit){      

        hit = true

        this.gotoAndStop(2)

    } else {      

        this.gotoAndStop(3)

  removeEventListener(Event.ENTER_FRAME, enterFrameEvents);

_root.brickAmt --;

I have animation playing inside frame 3 at the end of which goes to (parent) frame 4. How can I tell it if the current frame is 4 to do  _root.brickAmt --;  At this point? Is there another command I can use?

    

Thanks!

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 28, 2014

You appear to be mixing AS2 and AS3 code.  That will not work.  "_root" is an AS2 term.  In AS3 ir would be "MovieClip(root)".

In AS3 the current frame can be determined using the "currentFrame" property

I cannot tell from what you describe which timline you are dealing with so I will leave it at the following rough description...

if(currentFrame == 4){

    MovieClip(root).brickAmt --;

}

November 28, 2014

I am sorry I tried to change my question just now and it would not let me. From this code not the other one. What do i add?

_root = MovieClip(root);

  if (this.hitTestObject(_root.mcBall)){ 

       _root.ballYSpeed *= -1 

       if (this.currentFrame == 1){   

        this.gotoAndStop(2)

        } else {                     

        this.gotoAndStop(3)

        removeEventListener(Event.ENTER_FRAME, enterFrameEvents);

        _root.brickAmt --;

  }

  }

  }

}

}

December 2, 2014

Thank you. You are right. I was just trying to have a second or two after going to frame 3 and before executing brickAmt--.


I tried it like this and it works except is not playing the animation on Fr3 which stops on frame 40 which I called Fr4

if (this.hitTestObject(_root.mcBall)){

             if (this.currentLabel == 'Fr1'){  

                  this.gotoAndStop('Fr2')

             } else if (this.currentLabel == 'Fr2') {                    

                  this.gotoAndPlay('Fr3')

     removeEventListener(Event.ENTER_FRAME, enterFrameEvents);

                  _root.brickAmt --;

            }

Can you please tell me if I want to delay the execution of brickAmt-- after this.gotoAndPlay('Fr3'). How can I do it? Can I say something like  this.gotoAndPlay('Fr3' to Fr4) or something like that? Thanks?