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

About current frame property

Guest
Nov 28, 2014 Nov 28, 2014

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!

TOPICS
ActionScript
1.6K
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
LEGEND ,
Nov 28, 2014 Nov 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 --;

}

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
Guest
Nov 28, 2014 Nov 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 --;

  }

  }

  }

}

}

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
LEGEND ,
Nov 28, 2014 Nov 28, 2014

What do you add to accomplish what?  Look at what I already offered and think about it before you respond

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
Guest
Nov 29, 2014 Nov 29, 2014

Yes I am sorry.... tried that 1 week ago..... Its the most logical solution and it would not work......Can I put "if" statement after "if" "else??...... This is the whole code. and the _root.brickAmt--; at the end is not responding....If I don't have   if (this.currentFrame == 4)... It works. May I ask why?

public class Sinote extends MovieClip {

  private var _root:MovieClip;

  public function Sinote(){

  addEventListener(Event.ADDED, beginClass);

  addEventListener(Event.ENTER_FRAME, enterFrameEvents);

  }

  private function beginClass(event:Event):void{

  _root = MovieClip(root);

  _root.brickAmt ++;

  }

  private function enterFrameEvents(event:Event):void{

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

              _root.ballYSpeed *= -1 

             if (this.currentFrame == 1){   

        this.gotoAndStop(2)

        } else {                     

        this.gotoAndStop(3)

  if (this.currentFrame == 4){

  removeEventListener(Event.ENTER_FRAME, enterFrameEvents);

  _root.brickAmt --;

}

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
LEGEND ,
Nov 29, 2014 Nov 29, 2014

Yes you can combine if/else tests in a logical manner.  Your problem might be the logical part.

As long as you are telling it to go to frame 3 before you test if it is frame 4 then you can expect that you will not be in frame 4 when you are testing for it.  You probably need to decide what logic is needed to control when it goes to frame 3.

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
Guest
Nov 29, 2014 Nov 29, 2014

I want to tell it

if (this.hitTestObject_root.mcBall )

          this.gotoAndStop(2)

if (this.hitTestObject_root.mcBall ) Second time

          this.gotoAndStop(3)

  if (this.currentFrame == 4){

  _root.brickAmt --;

Can you please tell me the code to achieve this?

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
LEGEND ,
Nov 29, 2014 Nov 29, 2014

I don't think that is what you want to tell it since it is doing the same thing as before... telling it to go to frame 3 and then checking if it is in frame 4 right after that.

Why don't you use 'else / if ' logic and test for each frame where you would take action...

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

              _root.ballYSpeed *= -1 

             if (this.currentFrame == 1){   

                  this.gotoAndStop(2)

             } else if (this.currentFrame == 2) {                     

                  this.gotoAndStop(3)

            } else if (this.currentFrame == 3) { 

                 this.gotoAndStop(4)

            } else if (this.currentFrame == 4){

                  removeEventListener(Event.ENTER_FRAME, enterFrameEvents);

                  _root.brickAmt --;

            }

}

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
Guest
Nov 29, 2014 Nov 29, 2014

Thank you! It does not work. When it goes to frame 3 there is a nested animation, at the end of which has a command MovieClip(parent).gotoAndStop(4); And when it comes out to that frame four I need to somehow independently check if I am on that frame ( or frame 5 does not matter) and then issue the command _root.brickAmt --;... is there another way to achieve this?

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
LEGEND ,
Nov 29, 2014 Nov 29, 2014

If going to frame 4 is supposed to execute that line of code then just put that line of code in frame 4.

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
Guest
Nov 30, 2014 Nov 30, 2014

After the animation is played it does not work in any configuration for some reason.I even rearranged the animation to be on the main timeline in the object. This time it was coming up to frame 40 and still was not getting the result for some reason. It only works up to before is played. I am going to use set timeout property Can you please tell me how to use it in that instance? Or do I have to make another function and restructure the whole code?

if (this.currentFrame == 1){  

                  this.gotoAndStop(2)

             } else if (this.currentFrame == 2) {                    

      set timeout    this.gotoAndStop(3)

            }

Thanks!

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
LEGEND ,
Nov 30, 2014 Nov 30, 2014

I have no idea what you are trying to do with "set timeout" in the middle of nowhere.  Try looking it up in the help files or thru Google to see how it is used properly

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
Guest
Dec 01, 2014 Dec 01, 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--.

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
Guest
Dec 02, 2014 Dec 02, 2014
LATEST

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?

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