Flex – passed the parameters of the Flashvars style to the loaded SWF

I have a Flex 3 application (player v9) that loads Flash SWF (AS3, also player v9), and needs to dynamically pass a set of parameters known at runtime. These parameters Usually passed through the flashvars element in the HTML page. Embedded movies access these parameters through the loaderInfo.parameters object.

I have tried using the SWFLoader and Loader classes, but there is no success in passing param.

/p>

Related details:

>This is a local program and cannot rely on query string parameters.
>I have set loaderInfo.parameters [“foo”] = from the embedded code “123”, but the parameters never seem to appear in the embedded movie.
>I can’t put additional parameter passing mechanisms in the embedded movie because they are created by a third party.

< /div>

Passing this parameter in the URL will not help, because they are done using javascript code in html-wrapper.
‘flashVars’ parameters are obtained using Application.application.parameters, therefore, you must manually set these parameters in your case.

If you use SWFLoader to load another application, you You should create an object that will represent the loaded application and apply everything you need:


import mx.managers. SystemManager;
import mx.controls.Alert;
import mx.events.FlexEvent;

private var loadedApp:Application;

private function onLoadComplete( event:Event):void {
var smAppLoaded:SystemManager = SystemMan ager(event.target.content);
smAppLoaded.addEventListener(FlexEvent.APPLICATION_COMPLETE, onLoadedAppComplete);
}

private function onLoadedAppComplete(event:FlexEvent):void {
try {
loadedApp = Application(event.target.application);
if(!loadedApp) throw new Error();

loadedApp.parameters["param1"] = "value1";
} catch (e:Error) {
Alert.show("Failed to get application loaded.", "Error", Alert.OK);
}
}

private function onLoadError():void {
Alert.show("Failed to load an application.", "Error", Alert.OK);
}

]]>


width="100%" height="100%"< br /> source="./AppToLoad.swf"
complete="onLoadComplete(event)"
ioError="onLoadError()" securityError="onLoadError()" />

I have a Flex 3 application (player v9) that loads Flash SWF (AS3, also player v9), and needs to dynamically pass a set of known at runtime Parameters. These parameters are usually passed through the flashvars element in the HTML page. Embedded movies access these parameters through the loaderInfo.parameters object.

I have tried using the SWFLoader and Loader classes, but in terms of param passing No success.

Related details:

>This is a local program and cannot rely on query string parameters.
>I have set loaderInfo.parameters [” from the embedded code foo”] = “123”, but the parameters never seem to appear in the embedded movie.
>I can’t put additional parameter passing mechanisms in the embedded movie because they are created by a third party.< /p>

Passing this parameter in the URL will not help, because they are done using javascript code in html-wrapper.
The’flashVars’ parameter is using Application .application.parameters, so you have to manually set these parameters in your case.

If you use SWFLoader to load another application, you should create an object that will represent Load the application and apply everything you need:


import mx.managers.SystemManager;
import mx .controls.Alert;
import mx.events.FlexEvent;

private var loadedApp:Application;

private function onLoadComplete(event:Event):void {< br /> var smAppLoaded:SystemManager = SystemManager(event.target.content);
smAppLoaded.addEventLi stener(FlexEvent.APPLICATION_COMPLETE, onLoadedAppComplete);
}

private function onLoadedAppComplete(event:FlexEvent):void {
try {
loadedApp = Application(event.target) .application);
if(!loadedApp) throw new Error();

loadedApp.parameters["param1"] = "value1";
} catch (e:Error ) {
Alert.show("Failed to get application loaded.", "Error", Alert.OK);
}
}

private function onLoadError( ):void {
Alert.show("Failed to load an application.", "Error", Alert.OK);
}

]]>


width="100%" height="100%"
source="./AppToLoad.swf"
complete="onLoadComplete(event)"
ioError="onLoadError()" securityError="onLoadError()" />

Leave a Comment

Your email address will not be published.