I´m trying to extend the Loader class.
I want to store a variable on it.
Example:
package
{
import flash.display.Loader;
public class MyLoader extends Loader
{
private var _typeOfGallery:String
public function MyLoader()
{
super()
}
public function set typeOfGallery(value:String):void
{
_typeOfGallery = value
}
public function get typeOfGallery():String
{
return _typeOfGallery
}
}
}
Then I´m using like this:
var loader:MyLoader = new MyLoader()
loader.typeOfGallery = 'games'
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded)
function loaded(e:Event):void{
trace(e.target.typeOfGallery)
}
I´m receiving this error:
ReferenceError: Error #1069: Property typeOfGallery not found in flash.display.LoaderInfo and has no pattern value.
(I have translated from portuguese to english the error message)
How could I extend Loader so I don´t receive this error?
Thanks.
Loader
does not dispatch the Event.COMPLETE
event. You should listen to
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded)
and then get your MyLoader
with
function loaded(e:Event):void{
trace(((e.currentTarget as LoaderInfo).loader as MyLoader).typeOfGallery);
}
In your code, e.target
is a LoaderInfo
because the COMPLETE
event bubbles to the Loader
itself.