Reputation: 1860
i have a function(initialize) inside the a.as File.i want to access the that Variable from aaa.fla file?.How Can i access the Variable?my main class is a.as file ,inside a.as file i load the aaa.swf file AnyBody Help me Thanks in advance!
public function initialize(parameters:Object, stage:Stage,
loaderInfo:LoaderInfo, pluginHostWhitelist:Array):void
{
sourceId=loaderInfo.parameters.src;
addText();//Inside this function i load the aaa.swf file,
//here i want to access the variable "sourceId"
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
addText(){
_loader.load(new URLRequest("aaa.swf"));//while running this a.as i want to get the Sourceid Value
mainContainer.addChild(_loader);
}
My aaa.fla Its in Another place
import fl.motion.ColorMatrix;
import flash.filters.ColorMatrixFilter;
var sourceId:String// here i want to access the "sourceid" variable from a.as file
trace(sourceId)
Upvotes: 0
Views: 1027
Reputation: 9572
-------------------------- start edit -----------------------------------
A .fla file is a Flash IDE document!
Where does your sourceId variable come from?
In your example, it seems to come from flashvars, meaning that you would get the value from your SWF embedding code.
If this is the case, this wouldn't be relevant in your .fla file, because you wouldn't load an external swf using HTML embedded code.
Let's forget about flashvars for the time being... Are you using a Document Class with your .fla file? If not, I would advise you to, it'd make coding a lot easier. If yes, I suppose that you would load the external SWF there.
In the external SWF you could event use Custom Event Dispatching to pass your vars...
//in your external SWF
private function onAddedToStage( event:Event ):void
{
//you could use a Custom Event
//do some research on AS3 custom events...
var idEvent:YourEvent = new YourEvent();
idEvent.sourceId = sourceID;
this.dispatchEvent( idEvent );
}
//then in your .fla's Document Class
private var sourceId:Object;
private function addExternalSwf( event:Event ):void
{
var external:MovieClip = event.currentTarget.content as MovieClip;
external.addEventListener( YourEvent.SOURCE_ID , idEventListener );
addChild( external );
//remove addExternalSwf listener here...
}
private function idEventListener( event:YourEvent ):void
{
sourceId = event.sourceId;
//remove idEventListener listener here...
}
---------------------- end edit -----------------------------
Your question is really not clear... I can only go by the code example you give
public function initialize(parameters:Object, stage:Stage,
loaderInfo:LoaderInfo, pluginHostWhitelist:Array):void
{
//here you're retrieving the sourceID variable
//from the loaded SWF
sourceId=loaderInfo.parameters.src;
//Inside this function i load the a.swf file,
//here i want to access the variable "sourceId"...???
if( sourceId != null )
addText( sourceId );
else
trace('sourceID has a null value!!!!');
//why do you remove the event listener here
//and not within the onAddedToStage method???
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function addText(sourceId:Object):void
{
//....
}
Upvotes: 1
Reputation: 6961
The way your question is worded, it's hard to be sure what yo're really asking, but it seems to me that you're looking for a way to get the sourceId variable into the loaded swf.
First I should explain that trying to read it from within the swf is bad practice--child objects should not know about parent objects. So I'm not going to answer the question as asked.
One thing you may not be aware of is that DisplayObject has access to its own loaderInfo property, so you probably don't need to get this value from the outside in this specific instance.
As a more general matter, you can expose a public property on the document Class you use in the swf, and then you can cast the loaderInfo.content to that Class and then set that property to sourceId from the function in the parent.
Upvotes: 1
Reputation: 22604
There are many ways to do this, and I won't get into all of them.
But the easiest way is probably to cast your loaded SWF to Object (which is a dynamic class, so it will accept unknown member names) and add the property there, like so (I assume you use a Loader to load it, since you haven't posted the actual loading code):
Object(loader.content).sourceId = sourceId;
or you could also use bracket syntax:
loader.content["sourceId"] = sourceId;
The loaded SWF then doesn't need to know anything about outside classes and can use its own variable. The only thing you have to take care of is that either a) the SWFs base class is a dynamic class, such as MovieClip, or b) if you have a non-dynamic base class, make sure it has a public variable or setter method called sourceId
.
If you need more compilation time type checking, you can also have your SWF implement an interface and cast to that interface instead of Object.
Upvotes: 1