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:
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: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 }
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://bowserX = (stage.stageWidth / 2)-(bowserTilesWidth / 2); -- old code bowserX = (stageRef.stageWidth / 2)-(bowserTilesWidth / 2); //New code, with stageRef
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.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) }
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.




Reply With Quote