A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: importing animation controller

Threaded View

  1. #5
    Junior Member
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    21
    Yep, it would probably be the stage thing. If you're importing animation.as into Main.as, you would need to pass down the stage from Main.as to animation.as. How you do this is easy, just make an argument and a variable to hold the stage reference.

    You would add a global variable for the class, then in the public function animation(), you would add an argument, like so:

    Code:
    private var stageRef:Stage; //This is the global stage reference variable
    
    public function animation(stageRef:Stage){
        this.stageRef = stageRef; //Sets the global stage reference variable (above) to the stage passed through as an argument
    }
    So now that you have a stage container, anywhere that you want to reference "stage" in animation.as gets replaced with "stageRef". E.g.

    Code:
    //bowserX = (stage.stageWidth / 2)-(bowserTilesWidth / 2); -- old code
    bowserX = (stageRef.stageWidth / 2)-(bowserTilesWidth / 2); //New code, with stageRef
    Now to pass the stage down from Main.as is simple. Import your animation class in Main.as and create a new instance of it:

    Code:
    import assetsTest.animation //I think this is the file path for animation.as, not sure, make sure to double check
    
    public function Main(){
        var anim:animation = new animation(stage); //Set up a new instance of animation.as, passing the stage along with it as a variable
        addChild(anim); //Add the object, as currently, in animation.as, addChild will be adding objects inside of animation.as, not to the stage. Adding our instance of animation.as will allow us to see everything (if we don't add it, we don't see anything)
    }
    I might be a bit wrong here, I'm not sure. But definitely with the stage reference, it's fine to do that, you just need to pass it through to children and stuff so that they're not referencing something that's non-existant.

    If it isn't working I'd be happy to have a look at the source files if you'd like and see what I can do.
    Last edited by Danny22; 04-15-2012 at 10:44 PM.

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