Jump to content
Search Community

Subloading on a 3 swf setup

Amit test
Moderator Tag

Recommended Posts

Hi,

Thanks for this great utility and for the time spent in creating it!

 

I'm working on a project which has 3 swf, first swf_1 is a traditional preloader (not using loaderMax) which loads in swf_2, swf_2 shows some content (video, text again not using loaderMax) and ui and than when the user clicks some button I'm starting to load swf_3 USING SWFLoader.

 

swf_3, in itself, loads some xml (not using loaderMax), parses this xml and than creates a new LoaderMax and appends 100 (roughly) mp3 to it using requireWithRoot:this.root, my problem is that the progress is not shown on swf_2 and the SWFLoader on swf_2 doesn't seem to take in account the weight of the mp3 assets in swf_3.

 

I looked around and: tracing this.root from inside swf_3 gives me swf_3 as an object (should it bring back swf_2 to work?), I'm also using estimatedBytes:10067434 in SWFLoader (which is in swf_2).

 

Its worth noting that this is an ActionScript 3 project built in Flash builder, so I don't have frames, code outside of classes etc.

 

This is what's happening in swf_2:

//this is inside a class
private function skipVideo(event:MouseEvent):void{
		videoPlayer.kill();
		removeChild(videoPlayer);
		removeChild(skipBtn);

		//start the load
		_swfLoader = new SWFLoader("../../ProjectName/Deploy/App.swf",
			{ x:0, y:0,  estimatedBytes:10067434, onComplete:_completeHandler } );

		_progressDisplay = new ProgressCircleLite({radius:26, thickness:4, trackColor:0xFFFFFF, trackAlpha:0.25, trackThickness:4, autoTransition:false, smoothProgress:0});
		this.addChild(_progressDisplay);
		_progressDisplay.mouseEnabled = false;
		_progressDisplay.x = 69;
		_progressDisplay.y = 389;
		_progressDisplay.addLoader(_swfLoader);
		_swfLoader.vars.integrateProgress = true;
		_swfLoader.load(true);
	}

	private function _completeHandler(event:LoaderEvent):void {
		//add the SWFLoader's content to the stage
		addChildAt(event.target.content, 0);
	}

 

And this is what's happening in swf_3 (the loaded swf, which is also called App.swf in the above code):

//this is inside a class

private var xml:XML;
private var queue:LoaderMax = new LoaderMax();

public function App() {
                       //constructer
		super();
		this.addEventListener(Event.ADDED_TO_STAGE, init);
	}

	private function init(event:Event):void{
		this.removeEventListener(Event.ADDED_TO_STAGE, init);
		loadXML();
		buildUI();
	}

	private function loadXML():void{
		var loader:URLLoader = new URLLoader;
		loader.addEventListener(Event.COMPLETE, completeLoadingXML);
		loader.load(new URLRequest("assets/assets.xml"));
	}

	private function completeLoadingXML(event:Event):void {
		//parse XML
		var result:XML = new XML(event.target.data);

		trace(this.root.parent);

		queue.vars = { name:"childQueue",
						requireWithRoot:this.root,
						maxConnections:1,
						onChildComplete:_childCompleteHandler };

		for ( var i:int = 0; i < result.instrument.length(); i++ ) {

			queue.append( new MP3Loader( result.instrument[i].toString(),
				{ name: result.instrument[i].@type.toString() + result.instrument[i].@chord.toString(),
				  volume: result.instrument[i].@volume,
				  requireWithRoot: this.root,
				  noCache: true,
				  autoPlay:false } ) );
		}
		queue.load();
	}

 

Thanks!

Link to comment
Share on other sites

Hello Amit,

 

I am not experienced with subloading so deeply, and quite honestly root as opposed to _root still hangs me up sometimes.

 

BUT based on Jack's response here:

viewtopic.php?f=6&t=4869&p=19825&hilit=requirewithroot#p19825

 

I believe that it is possible that since your mp3 loadermax queue isn't populated until AFTER your xml loads the requireWithRoot is being set too late.

 

I notice that you do instantiate your queue at the top of your class. so it does exist on frame 1.

 

Try passing in the queue vars when you create it (top of class). If that doesn't work, make your queue public. If that doesn't work... I don't know.

 

Please post back with your results. I'm sure there are others that can help you if needed.

 

Carl

 

ps. what's up with all the loading going on without LoaderMax? :)

Link to comment
Share on other sites

hi,

 

Thanks for the fast reply, unfortunately neither helped.. a couple of things I noticed though: this.root is not acceptable when declared in the top of the class, and instantiating LoaderMax at the top (outside of any function), private or public, doesn't even start the load..

 

Thanks anyhow!

Link to comment
Share on other sites

If I understand your description properly, the problem is indeed that your loaders aren't created/populated yet when the SWFLoader scans for loaders that have requireWithRoot set to that swf's root. You said you manually load XML (not using XMLLoader) and THEN (after the XML loads), you dump stuff into a LoaderMax that you want to be required with that swf. No-can-do. It's simply impossible because SWFLoader can't find instances that don't exist yet on the first frame. See what I mean? And it can't just wait indefinitely until your XML loads and you parse the data.

 

Why not use an XMLLoader with its requireWithRoot set? That seems like it'd solve the 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...