A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [CS3] [Question] Elements on scene not loaded before constructor is called

  1. #1
    Junior Member
    Join Date
    Sep 2008
    Posts
    1

    [CS3] [Question] Elements on scene not loaded before constructor is called

    Hi,
    This not totally related to games development, but I think will likely be a common Game Dev problem. I am fairly new to Flash, but have not found through google searching any concrete answers.

    I have written a game that runs in a single frame. The frame contains some elements (a button, some score textfields etc) and the rest of the game is built up using AS3.
    Now I have completed the game engine, I wanted to put in a loader, a start game frame (so that the game doesn't start immediately) and a frame at the end to show their final score.

    So, I did the following...
    - Converted all the elements on the stage to be a movie clip
    - renamed the AS3 class to the name of the movie clip rather than using the document class (so the ActionScript was not called immediately on startup)
    - created a new keyframe and placed the Game movieclip on the frame

    This all seems to have had the desired effect (the script is called when frame 2 starts), but I get AS run time errors saying that the button and text fields are null or cannot be found. Reading around the internet, it appears that this is because the items on the stage have not loaded by time the actionscript is called.
    I would rather not have to build up the stage programmatically in AS3 (otherwise what is the point in using Flash, I may as well just use Java to write games!).

    Any help would be greatfully received.
    Thanks
    Codemwnci

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    AS3 != scripting
    its now programming- sad but trues for now. Maybe wait till CS4 will be released as its to be expected that they smooth workflow alot for those who like to work with the IDE and AS3 together.

  3. #3
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Display objects on main timeline or its children are accesibble to the classes created on same frame. Just dont assign Game class to the movie clip, keep them all separated and it should work.

  4. #4
    Professional Flash Developer
    Join Date
    Aug 2007
    Location
    California
    Posts
    105
    Obviously what Tonypa said will work, but you can also use a document class:

    You could also let the movie play passed the 2nd frame and stop on frame 3 (hack). In CS3, that will allow the AS3 code to use all object that were initialized on frame 2.

    With this method, you can still use a document class, but you need to put all of your assets on frame two. Your document class runs frame 1 and pre-loads, once done, it passed through frame 2 (all of your assets can be hidden in this frame inside a holder, off stage). and stops on frame 3. Your game can continue to run in frame 3 perpetually while your document class controls everything.

    To pre-load properly you will need to set all of your exported library items NOT check the "export on first frame button". That is what the frame 2 asset holder is for.

    Anyway, it sounds lame, but it works very well.

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