mercredi 23 septembre 2015

Setting Class from External SWF - Implicit Coercion

I'm trying to load in an SWF into my main file. The SWF is ColorWheel.swf, and the main file is c_test.as. Here is my code:

var loader:Loader = new Loader();   
this.addChild(loader);
loader.load(new URLRequest("ColorWheel.swf"));  
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageLoaded);
var myClass:Class;

function imageLoaded(e:Event):Class
{
   loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,imageLoaded);    
   return loader.contentLoaderInfo.applicationDomain.getDefinition("StageColorWheel") as Class;
}

myClass = imageLoaded;
var myWheel:BitmapData = new myClass();

This gives me an implicit coercion error where I have myClass = imageLoaded. I'm fairly certain this is an easy fix, but if anyone has an answer I'd much appreciate it. This was my current code before (which worked, but everything following loading the swf into c_test.as was included in the imageLoaded function.

var loader:Loader = new Loader();   
this.addChild(loader);
loader.load(new URLRequest("ColorWheel.swf"));  
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageLoaded);
var myClass:Class;

function imageLoaded(e:Event):Class
{
   loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,imageLoaded);    
   myClass = loader.contentLoaderInfo.applicationDomain.getDefinition("StageColorWheel") as Class;

   var myWheel:BitmapData = new myClass();
   //rest of code - works
}

Aucun commentaire:

Enregistrer un commentaire