Solved

Flash ActionScript

Posted on 2016-11-07
6
21 Views
Last Modified: 2016-11-08
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
0
Comment
Question by:AXISHK
  • 3
  • 3
6 Comments
 
LVL 19

Expert Comment

by:quizengine
Comment Utility
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.
0
 

Author Comment

by:AXISHK
Comment Utility
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.
0
 
LVL 19

Expert Comment

by:quizengine
Comment Utility
"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
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:AXISHK
Comment Utility
How about "this" and "_root" mean ?

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

Thx
0
 
LVL 19

Accepted Solution

by:
quizengine earned 500 total points
Comment Utility
_root is the 'top' movieclip / timeline - if you like, the 'biggest' of the russian dolls. This is a quick way for a very 'buried' (nested) movieclip to refer to the 'top' parent. (Otherwise a movieclip that was buried might have to use something like _parent._parent._parent,_parent... etc)

 The onEnterframe code continues to run UNTIL the test

       if (this.hitTest(_root._xmouse, _root._ymouse, true) != true)

comes out as 'true', and then the code

     delete onEnterFrame;

runs, which deletes this whole block of code.
0
 

Author Closing Comment

by:AXISHK
Comment Utility
Thx
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now