flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jerry Hamby <jerryha...@vdex.com>
Subject Re: No access to MX:SWFLoader "content" after dynamic loading a SWF file
Date Tue, 02 Dec 2014 16:18:08 GMT
Thanks everyone, I ended up using this code successfully:

private function laodMySWF():void {
	// load the file with URLLoader into a bytearray
	var loader:URLLoader=new URLLoader();
	
	// binary format since it a SWF
	loader.dataFormat=URLLoaderDataFormat.BINARY;
	loader.addEventListener(Event.COMPLETE, onSWFLoaded);
	
	//load the file
	loader.load(new URLRequest("/swfs/welcome_16_9.swf"));
}
private function onSWFLoaded(e:Event):void {
	// remove the event
	var loader:URLLoader=URLLoader(e.target);
	loader.removeEventListener(Event.COMPLETE, onSWFLoaded);
	
	// add an Application context and allow bytecode execution 
	var context:LoaderContext=new LoaderContext();
	context.allowLoadBytesCodeExecution=true;
	
	// set the new context on SWFLoader
	loader1.loaderContext = context;
	
	loader1.addEventListener(Event.COMPLETE, loadComplete);
	
	// load the data from the bytearray
	loader1.load(loader.data);
}

// your load complete function
private function loadComplete(completeEvent:Event):void {
	trace("loadComplete: completeEvent.target.content " + completeEvent.target.content);
	mySwfMc = loader1.content as MovieClip;
	loader1.content.addEventListener("MessageFromFlash", doSomething);
}

On Dec 1, 2014, at 8:13 PM, Alex Harui wrote:

> Sounds like AIR Security Model stuff.  See “Adobe Air sandbox” in this
> article [1].  A commonly used workaround is to use byte array as described
> in the first answer here [2].
> 
> HTH,
> -Alex
> 
> [1] 
> http://www.adobe.com/devnet/flashplatform/whitepapers/runtime-security.html
> [1] http://s.apache.org/AdobeAIRRuntimeSecurity
> [2] 
> http://stackoverflow.com/questions/2713865/how-to-run-an-external-swf-insid
> e-a-flex-application
> [2] http://s.apache.org/ByteArraySWFLoader
> 
> On 12/1/14, 3:43 PM, "Jerry Hamby" <jerryhamby@vdex.com> wrote:
> 
>> I have in my Flex app (Apache SDK  4.12.1):
>> <mx:SWFLoader id="loader1" creationComplete="swfLoaded(event)"
>> complete="contentLoaded(event)"/>
>> 
>> I use the code below to find the SWF file: (this seems to work for both
>> the desktop and on my Android device)
>> var theFile_ApplicationStorageDirectory:File =
>> File.applicationStorageDirectory.resolvePath("/swfs/welcome_16_9.swf");
>> var thePath:* = theFile_ApplicationStorageDirectory.nativePath;
>> loader1.load(thePath);
>> 
>> this works fine now after hours of research but the problem is that I
>> can't get access to "loader1.content", it is always null.
>> I need it so I can do an addEventListener:
>> loader1.content.addEventListener("MessageFromFlash", doSomething);
>> 
>> I get the "swfLoaded" event but not the "contentLoaded" event.
>> 
>> Any clues on why the loader1.content is NULL?
>> 
>> Jerry
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message