Wednesday, September 18, 2013

Flex Hints

List Object Properties
for(var id:String in object) {
var value:Object = object[id];
trace(id + " = " + value);
}

Application-sandbox content ERROR

Solution 1
work on the web and as an app. (apps don't need to allowDomain b/c they can download everything by default and that is why it fails.)
try {Security.allowDomain("*");}catch (e) { };


Solution 2
Or try to load your SWF temporarily into a ByteArray and then load it with your SWFLoader.
Don't forget to set allowLoadBytesCodeExecution to true since your SWF has as code inside.
Of course be sure that your loaded swf is secure enough for your application since it will have access at all your property.
private function loadSwfApplication():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("path/to/the/application.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
 sfwLoader.loaderContext = context;

 sfwLoader.addEventListener(Event.COMPLETE, loadComplete);

 // load the data from the bytearray
 sfwLoader.load(loader.data);
}

// your load complete function
private function loadComplete(completeEvent:Event):void {
 var swfApplication:* = completeEvent.target.content;
 swfApplication.init();  // this is a Function that I made it in the Root 
                         // class of swfApplication
}

0 comments:

Post a Comment