-
AS3: Code in a single frame or in multple frames
I have a button that I want to work on multiple frames. Currently, I have a scene that automatically starts to play when the playhead enters the first frame (no stop command). I have an event listener in the first frame that listens for a click. After the click the user is supposed to go to another scene.
The problem is that the button is not working. I am assuming that the code in the first frame only applies to the first frame and I need to add additional code that applies as the playhead is playing across the multiple frames.
Please help!
Here's the code:
goBackMain_bnt.addEventListener(MouseEvent.CLICK, goBack);
function goBack(event:MouseEvent):void
{
gotoAndStop(1,"ShortA");
}
-
Code you write on frame 1 will still work on other frames, because the event is added to the object, not the frame. (Similarly, you can also call functions that were created on frame 1 later in the timeline.) One caveat to be careful of - if you ever return to frame 1, any code not inside a function WILL be executed again.
Anyway, to the issue at hand -- Do you have multiple keyframes on the button? And if so, is the instance name blank on those keyframes? Makes sure the name is consistent across all keyframes.
-
"Do you have multiple keyframes on the button? And if so, is the instance name blank on those keyframes? Makes sure the name is consistent across all keyframes."
The scene has several layers. The code in question is on the top layer called "actions." I also have a few keyframes on the "actions" layer that I have given names to. For example, I have named a frame "scene 2," "scene 3" etc. Only the frame is named though; no other code is on the "actions" layer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|