A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: AS3: Code in a single frame or in multple frames

  1. #1
    Member
    Join Date
    Nov 2007
    Location
    Los Angeles, CA
    Posts
    32

    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.addEventListene​r(MouseEvent.CLICK, goBack);

    function goBack(event:MouseEvent):void
    {
    gotoAndStop(1,"ShortA");
    }

  2. #2
    Senior Member
    Join Date
    Jun 2003
    Location
    Kent, WA
    Posts
    536
    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.

  3. #3
    Member
    Join Date
    Nov 2007
    Location
    Los Angeles, CA
    Posts
    32
    "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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center