Link to home
Start Free TrialLog in
Avatar of AXISHK
AXISHK

asked on

Flash ActionScript

Any idea when the script "gotoAndPlay("menuClose")" at Frame 12 be executed ? In AS layer, frame 12 ha execute "stop". It seems that code at frame 12 never be executed. Any idea ?

Thx
001.fla
Avatar of quizengine
quizengine
Flag of United Kingdom of Great Britain and Northern Ireland image

1. Open the fla. You will need to do this in Flash CS6 (or earlier version) as the file is Actionscript 2, and versions of Flash and Animate after CS6 don't support Actionscript 2.

2. Double click the 'menu' movieclip (the one that has the text 'Photos' in it)

3. Single click the button (that also has 'Photos' text on it).

4. Look at the 'Actions' panel (F9 if it isn't open).

5. You will see the code
   on(release){
         gotoAndPlay("menuOpen");
   }
This shows that when that button is clicked, this timeline will advance to the 'menuOpen' label (frame 2) and play, The playhead will  continue until it reaches frame 12 where it will stop, because of the 'stop();' command on frame 12 (AS layer).

6. Here's the crucial bit... The three layers 'hit text', 'sub btn' and 'btn' each have something interesting to look at.

7. btn layer. Single click the ''Photos' button. Look at the Actions panel. You will see
on(release){
               gotoAndPlay("menuClose");
}
This is one answer to your question about when the code will run. Answer - when this button is clicked.

8. sub btn layer. Click on either the button labelled  '001' or '002' and look at the Actions panel. On the '001' button you will see the code...
on (release) {
      _parent.gotoAndStop("f5");
      gotoAndPlay("menuClose");
}

and on the '002' button you will see the code

on (release) {
      _parent.gotoAndStop("f10");
      gotoAndPlay("menuClose");
}

In both cases, part of the code that's run is 'gotoAndPlay("menuClose");'
(NOTE, You must click the blue BOX that forms the button, and NOT the actual '001' or '002' text, which is just text, and not a button)

9. Lastly, the 'hit text' layer. In the version of the fla that I downloaded, this layer is locked. You will need to unlock it (click the padlock) to see this next bit.
Click anywhere over any part of the content on the stage, and you will select an invisible (alpha = 0) box. Look at the Actions panel. You will see

onClipEvent (enterFrame) {
      if (this.hitTest(_root._xmouse, _root._ymouse, true) != true) {
            delete onEnterFrame;
            _parent.play();
      }
}

This code is responsible for the runtime behaviour "If, after clicking the 'photos' button, you DON'T click again, but just move your mouse pointer away from all of the buttons, the menu 'collapses').

Hope that all helps.
Avatar of AXISHK
AXISHK

ASKER

What's the meaning of "delete onEnterFrame;" ? For " _parent.play();" does it mean flash will continue to play the remaining frames where it  previously stop ?

"this.hitTest(_root._xmouse, _root._ymouse, true) != true" - How does it check the mouse position ? For "this" and "_root", does it refers to hit text and scene1 respectively ?


Thx.
"delete onEnterFrame;"

An "onEnterFrame" event, runs all of the time, at the frame rate of the Flash movie. This means it is consuming 'resources' all the time it runs. So it's good programming practice to get rid of these events, once they're no longer useful. That's what "delete onEnterFrame;" does - it deletes 'itself'.

"_parent.play();"

Do you know 'Russian Dolls'? How you can have a doll inside a doll inside a doll (etc etc).

Well, Flash movieclips are the same. Think of the timeline that were working in, as a russian doll... It can have smaller dolls (other movieclips) inside of itself . These are called 'children'. And it works the other way too - if you are the 'child' of a movieclip, then it's your 'parent'.

Have a look here to learn more about this.

https://helpx.adobe.com/animate/using/multiple-timelines.html
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001345.html
Avatar of AXISHK

ASKER

How about "this" and "_root" mean ?

The frame delete itselft - do you mean it will not run the the code inside that frame ?

Thx
ASKER CERTIFIED SOLUTION
Avatar of quizengine
quizengine
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AXISHK

ASKER

Thx