Jump to content
GreenSock

mrEmpty

[SOLVED] Strange problem, probably not LoaderMax related.

Recommended Posts

Hello.

 

I have a strange problem, I'm using LoaderMax in the code but I don't think that's the problem. But as I really can't figure this out, and a simpler version of this code without LoaderMax works, I thought I'd post.

 

I have an empty MovieClip:

 

public var master:MovieClip = new MovieClip();

 

I'm using a for loop to run through an XMLList populated with stuff from an XMLLoader:

 

private function setupMain(event:LoaderEvent):void

{

trace("setupMain");

var panels:XMLList = event.target.content.panel;

trace(panels.length());

 

for (var i:int = 0; i < panels.length(); i++)

{

trace("for start");

var box:NavBox = new NavBox(800, 450);

master.addChild(box);

box.x = box.width * i;

box.y = 100;

trace(box.x);

trace(box.y);

}

}

 

The problem is, the instances of box do not appear. If I add them to the stage they do, but if I add them to master they don't. If I trace the positions it appears as if they are added to the display list, but they don't show up.

 

Now, if I ignore the entire loading thing this problem goes away. But I don't think LoaderMax is the issue at all.

 

Complete code just in case it helps:

 

package  {

import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.text.GridFitType;
import mx.core.BitmapAsset;
import flash.events.MouseEvent;

import com.greensock.loading.LoaderMax;
import com.greensock.loading.ImageLoader;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.XMLLoader;
import com.greensock.BlitMask;
import com.greensock.TweenMax;

import com.fingerpuk.ui.NavBox;


public class Treasures03 extends MovieClip {

	//embed the background image
	[Embed(source="assets/Grid.png")]
	const Grid:Class;

	//create master container
	public var master:MovieClip = new MovieClip();
	//create my BlitMask
	private var bMask:BlitMask = new BlitMask(master, 0, stage.stageHeight, stage.stageWidth, stage.stageHeight);


	public function Treasures03() {
		init();
	}

	private function init():void
	{
		//configure the BlitMask
		bMask.smoothing = true;
		bMask.wrap = true;

		//load the background image
		var grid:DisplayObject = new Grid();
		addChild(grid);

		//configure the master
		addChild(master);
		trace("master added");

		//load and parse the config xml
		var xmlLoader:XMLLoader = new XMLLoader("assets/config.xml", {onComplete:setupMain});
		xmlLoader.load();

		//set up test listener on stage, delete later
		master.addEventListener(MouseEvent.MOUSE_DOWN, testBlit);
	}


	private function setupMain(event:LoaderEvent):void
	{
		trace("setupMain");
		var panels:XMLList = event.target.content.panel;
		trace(panels.length());

		for (var i:int = 0; i < panels.length(); i++)
		{
			trace("for start");
			var box:NavBox = new NavBox(800, 450);
			master.addChild(box);
			box.x = box.width * i;
			box.y = 100;
			trace(box.x);
			trace(box.y);
		}
	}

	private function testBlit(event:MouseEvent):void
	{
		trace("testBlit");
		TweenMax.to(master, 3, {x:-3000, onUpdate:bMask.update});
	}
}

}

Link to comment
Share on other sites

I think your master should be should have boxes in it before you create a BlitMask for it.

in the first example I didn't see that master was on the display list. i didn't see addChild(master).

 

so even though you do master.addChild(somebox);

if master isn't added to the display list... you won't see any boxes.

Link to comment
Share on other sites

OK. I've moved the creation of the BlitMask to after the for loop:

 

private function setupMain(event:LoaderEvent):void
	{
		var panels:XMLList = event.target.content.panel;

		for (var i:int = 0; i < panels.length(); i++)
		{
			var box:NavBox = new NavBox(800, 450);
			master.addChild(box);
			box.x = box.width * i;
		}		
		confMaster();
	}

	private function confMaster():void
	{
		addChild(master);

		bMask = new BlitMask(master, 0, stage.stageHeight, stage.stageWidth, stage.stageHeight);
		bMask.smoothing = true;
		bMask.wrap = true;
	}

 

So now I'm loading the XML, creating an XMLList, using that to create my instance of NavBox and adding them to master. I then run a function (confMaster) that adds master (which has 5 instance of NavBox in it) and creates the blitmask. Still not joy though :(

Link to comment
Share on other sites

I solved it, it was the BlitMask.

 

The correct code is:

 

bMask = new BlitMask(master, master.x, master.y, master.width, master.height);

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.
×