Jump to content
Search Community

Accessing and controlling swfs that are loaded

quirksmode test
Moderator Tag

Recommended Posts

Hi,

 

absolutely loving these classes, though am having a few problems with them. I am basically trying to create a swf rotator that loads and then displays swfs 1 by 1 based on which number is selected from a navigation menu e.g. (1)(2)(3). I have managed to get the swfs to load fine, but the problem I am having is that they are being loaded as a contentDisplay element and not as MovieClips and as a result I am unable to directly access them. I found some help on your site about using rawContent to solve this problem but struggled to get it to work the way I want.

 

I need to pass variables in and also control the timeline of each of these swfs so ideally I would want to load them in with movieClip names of rotator1, rotator2, rotator3 etc. To control the timeline of these swfs I would want the code to be rotator1.gotoAndPlay("start");, rotator1.stop(); for example.

 

Other questions I have are:

 

1) Can loaderMax stop all movie clips within the swf and then autoplay once it is fully loaded?

2) I am using flashVars passed from the html to the swfs, does loaderMax have a clever way of passing these variables or should I just do this the normal way?

 

Here is my code so far:

 

thanks again!!

 

package demos
{
import com.greensock.TweenLite;
import com.greensock.easing.Back;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.LoaderMax;
import com.greensock.loading.SWFLoader;
import com.greensock.loading.display.ContentDisplay;

import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.events.MouseEvent;

public class GetLoader_Test extends Sprite
{

	private var nav_btn:MovieClip;

	private var navNum:uint = 1;


               private var urls:Array = ["swfs/testswf_01.swf","swfs/testswf_02.swf","swfs/testswf_03.swf"];
	private var rotator:ContentDisplay;


	public function GetLoader_Test()
	{


		//create a LoaderMax named "mainQueue" and set up onProgress, onComplete and onError listeners
		var queue:LoaderMax = new LoaderMax({name:"mainQueue",maxConnections:1,onProgress:_progressHandler,onComplete:_queueCompleteHandler});

		// Loop through urls and create a queue of swf loaders
		for (var i:Number = 0; i < urls.length; i++)
		{
			queue.append( new SWFLoader(urls[i], {name:"rotator_"+(i+1), autoPlay:false}) );
		}

		//prioritize the first swf named "rotator_1"
		LoaderMax.prioritize("rotator_1");


		queue.load();
	}

	private function _progressHandler(event:LoaderEvent):void
	{
		this.progress_mc.progressBar_mc.scaleX = event.target.progress;
	}

	private function _queueCompleteHandler(event:LoaderEvent):void
	{
		removeChild(progress_mc);

		rotator = LoaderMax.getContent("rotator_1");
		rotator.alpha = 0;
		swfContainer.addChild(rotator);
		TweenLite.to(rotator, 1, {alpha:1});


		// Create the nav buttons based on urls passed in
		for (var i:Number = 0; i < urls.length; i++)
		{
			nav_btn = new navNum_btn();
			nav_btn.name = "nav_btn_"+(i+1);
			nav_btn.x = i * nav_btn.width;
			nav_btn.y = 0;
			nav_btn.value_txt.text = (i+1);
			nav_btn.mouseEnabled = true;
			nav_btn.mouseChildren = false;
			navContainer.addChild(nav_btn);

                               // Assign _changeRotator click function to nav buttons
			nav_btn.addEventListener(MouseEvent.CLICK, _changeRotator, false, 0, true);

		}


	}

	private function _changeRotator(event:MouseEvent):void
	{
                      // Get the number of the button clicked based on the text found within it
		navNum = event.target.value_txt.text;
		// Fade the rotator out and remove it from stage
		TweenLite.to(rotator, 1, {alpha:0, onComplete:_fadeIn});
	}

	private function _fadeIn():void
	{
		swfContainer.removeChild(rotator);
		// Change and fade in the rotator based on the number clicked
		rotator = LoaderMax.getContent(urls[navNum - 1]);
		swfContainer.addChild(rotator);
		TweenLite.to(rotator, 1, {alpha:1});
	}
}
}

Link to comment
Share on other sites

...but the problem I am having is that they are being loaded as a contentDisplay element and not as MovieClips and as a result I am unable to directly access them. I found some help on your site about using rawContent to solve this problem but struggled to get it to work the way I want.

Sure, you can just use the raw content (the MovieClip) instead of the ContentDisplay wrapper like this:

 

rotator = LoaderMax.getLoader("rotator_1").rawContent;

 

(obviously make sure you change the data type of your rotator to MovieClip or DisplayObject).

 

1) Can loaderMax stop all movie clips within the swf and then autoplay once it is fully loaded?

 

No, if you set autoPlay to false, it will just stop() the main timeline of the subloaded swf, not all nested MovieClips too. If you want to play() when the loader completes, just use an onComplete to then call the rawContent's play() method.

 

2) I am using flashVars passed from the html to the swfs, does loaderMax have a clever way of passing these variables or should I just do this the normal way?

Yep, just do that the normal way. There isn't a fancy LoaderMax-specific way.

Link to comment
Share on other sites

Actually, one last question :-)

 

Using my code above which preloads the swfs and then adds and removes them from the stage 1 by 1, is there a way I can "reset" the swf when it gets added so it starts playing from the beginning again without having to force control of the timeline myself. For example when the first swf is added it plays from the first frame, but all the others seem to have already played and do not start fresh.

 

What I want is to basically refresh the swfs each time they get added to the stage so they play from the start, but without actually having to reload them each time if that makes sense?

Link to comment
Share on other sites

It depends how your sub-swf is built and what you mean by start "fresh". It's impossible (as far as I know) to prevent a swf from instantiating when it loads. It will run the code on its first frame as soon as it loads adequately. It will also start playing right away by default, but SWFLoader's autoPlay:false will basically stop() the root timeline. That doesn't affect nested MovieClip timelines though. So to truly restart your swf, you need to reload it altogether but keep in mind that after it loads the first time, it should be in your browser's cache so it'll load almost instantaneously.

 

If you just want to start the swf from the first frame again, just gotoAndPlay(1) on its root timeline.

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