Jump to content
Search Community

LoaderMax and Liquid Stage/Stage Align

LynnB test
Moderator Tag

Recommended Posts

I'm just starting out trying to use this new LoaderMax. I don't pretend to know much at all. To start, all I want to do is load my main.swf file. I do this and I get; Error #1009: Cannot access a property or method of a null object reference.

I figured out it may have to do with LiquidStage or the StageAlign class, I think! I take all references of it out of my main. swf and the Error #1009 disappears. So is it that LiquidStage or the Stage Align class is not loading before it's called? I'm not sure.

What to do?

 

Jack, I really wish you'd do a video tutorial on the basics of using LoaderMax. That would really help out us newbies!

Link to comment
Share on other sites

Yep, I do plan on doing a little video tutorial. Just not enough hours in the day to accomplish everything I want to do :)

 

The only thing I can think of as far as the 1009 error is that your subloaded swf may be trying to reference the stage before it was added to the display list (put on the stage) in which case the stage reference will be null. In other words, if on the first frame of your subloaded swf you have:

 

var ls:LiquidStage = new LiquidStage(this.stage, 550, 400);

 

When that code runs, "this.stage" will be null because that swf hasn't been added to the parent's stage. LiquidStage no like that :)

 

The solution is to add an ADDED_TO_STAGE listener in your subloaded swf so that it doesn't try to access "this.stage" until there is truly a stage. Like this:

 

//inside the constructor of the main class of your subloaded swf...
this.addEventListener(Event.ADDED_TO_STAGE, _addedToStageHandler);

private function _addedToStageHandler(event:Event):void {
   this.removeEventListener(Event.ADDED_TO_STAGE, _addedToStageHandler);
   var ls:LiquidStage = new LiquidStage(this.stage, 550, 400);
   //and so on...
}

 

Make sense?

Link to comment
Share on other sites

Thank you Jack! But to be blunt. I have no idea where to put this code. You said put it in the constructor of the main class in my subloaded swf (I know this to mean my main swf that I'm trying to load). I don't know where the main class is! Is it a .as file? Sorry for being such a newbie!

Link to comment
Share on other sites

Where's your LiquidStage code? It sounds like maybe you just put it on the main timeline of an FLA. Is that right? If so, you should be able to pretty much copy and paste the code I wrote above, but remove the "private" keyword (that's just for inside classes). In fact, if you want to make it so that it should work on its own or when its subloaded, you could do:

 

if (this.stage == null) {
   this.addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
} else {
   addedToStageHandler(null);
}

var ls:LiquidStage; //declaring it outside the function so it's available wherever you want - just make sure you don't run code that relies on it until it is properly defined in the addedToStageHandler().

function addedToStageHandler(event:Event=null):void {
   this.removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
   ls = new LiquidStage(this.stage, 550, 400);
   //and so on...
}

Link to comment
Share on other sites

Thanks again, Jack! Yes, my LiquidStage code is in the main timeline of my .fla. I tired your code and initially it didn't quite work. Still got the 1009 error. The below code is what I had to do. Is this correct, that I need to put my LiquidStage attach's in the function also? When I do, that nasty error disappears and things work fine. Putting the ls.attach's outside the function causes the error. Once again, thanks so much for your help. I'm ready to dig deeper now into LoaderMax.

 

if (this.stage == null) {
   this.addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
} else {
   addedToStageHandler(null);
}

var ls:LiquidStage; //declaring it outside the function so it's available wherever you want - just make sure you don't run code that relies on it until it is properly defined in the addedToStageHandler().

function addedToStageHandler(event:Event=null):void {
   this.removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
this.stage.align = StageAlign.TOP_LEFT;
       ls = new LiquidStage(this.stage, 550, 400);
ls.attach(orange_mc, ls.CENTER);
       ls.attach(blue_mc, ls.TOP_RIGHT);

   //and so on...
}

Link to comment
Share on other sites

  • 2 weeks later...

I'm back, Jack! :(

 

I'm having an issue now with LiquidPosiiton with items I have pinned to the stage that LoaderMax is throwing an 1009 error. I take out the liquidPostions and LoaderMax works fine. I suspected when I inserted LiquidPosition pins that this would happen.

How can I define LiquidPosition pins within the code you wrote above?

 

For instance this throws the error in LoaderMax:

 

timeline.insert(TweenMax.to(logo_mc.products, 1, {delay:4.5, liquidPosition:{x:183, y:112, pin:ls.CENTER},ease:Bounce.easeOut}));

Link to comment
Share on other sites

Did you make sure your tweening code runs AFTER you create your LiquidStage instance (which must happen after your clip is added to the stage)? I don't mean playing the tween after - I mean creating the tween itself. It needs to find the LiquidStage, so if it doesn't exist yet, that's a problem.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...