PDA

View Full Version : Instance name of loaded external swf


turb
06-24-2009, 06:51 PM
Hi,

I'm new to AS3 and have successfully loaded an external swf. When load is complete, I add the loader target content to a movieclip but I've got problem accessign it after.


// siteLoaderComplete
function siteLoaderComplete(e:Event)
{

// Set site holder
site.x = -500 + 50;
site.y = -600 + 100;
site.addChild(e.target.content);

}


The only problem is that it that right now, it add a child with a instance name of 'instance5' in site. But how can I change 'instance5' for another term like 'myContent'??

I need to be able to access content from the loaded swf.

Thank

Slowburn
06-24-2009, 08:26 PM
When you load an external SWF using the Loader Class, the document class is invoked and is added to the external SWF's stage automatically. because of this, you cannot give the loaded SWF a name. however, the Loader Class can be named and added to the timeline, ad you gain accesss to the external SWF by way of loader.content.

To make you life easier, you could declare a variable that holds a reference to the content of the loader.


var _reference:MovieClip = null;

var loader:Loader = new Loader();
loader.name = "externalMovie";
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, handleLoad, false, 0, true );
loader.load( new URLRequest( "ExternalMovie.swf" ) );

function handleLoad( event:Event ):void
{
event.target.removeEventListener( Event.COMPLETE, handleLoad, false );
// keep reference to the content
_reference = event.target.content as MovieClip;
// add loader to the display list so we can see the external SWF.
addChild( event.target.loader );
}

//now to manipulate the content...
_reference.visible = true;
_reference.x = 299.99;

// or

var theLoader:Loader = getChildByName( "externalMovie" ) as Loader;
theLoader.content.visible = false;
// etc...