So I have a question that (hopefully) somebody can answer quickly.
I’m making a component and I’ve found that a parameter that I make inspectable is not getting initialized early enough. Basically, I know I’m doing something wrong in the way I declare/use the variable, but I don’t know what. Perhaps my entire class structure is off.
Here’s the basic structure of the class:
package
{
import fl.core.UIComponent;
//More import statements...
public class Param extends UIComponent
{
//I don't want to initialize this, I'm doing it as an example. I want this value to be set by the user in the parameter inspector-thingie
protected var _paramSource:String = "pictureIDontWant.jpg";
//Other variables...
[Inspectable(type="String")]
public function get paramSource():String
{
return _paramSource;
}
public function set paramSource(param:String):void
{
_paramSource = param;
}
public function Param():void
{
}
override protected function configUI():void
{
super.configUI();
var paramLoader:UILoader = new UILoader();
trace(_paramSource); //Outputs: pictureIDontWant.jpg
var paramURL:URLRequest = new URLRequest(_paramSource);
paramLoader.load(paramURL);
paramLoader.addEventListener(Event.COMPLETE, loadedHandler);
paramLoader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
}
private function errorHandler(e:Event)
{
//Does stuff
}
private function loadedHandler(e:Event)
{
//Calls a function to get to the other stuff
trace(_paramSource); //Outputs: the user input from the component inspector
doSomethingUseful();
}
}
}
As you can see, the parameter picks up on the user’s input for the parameter, but too late (after the wrong picture is loaded). Is there any way I can get that variable initialized before I load it’s value via paramLoader?
Any help is hugely appreciated.