Reputation: 63349
var image:Image = new Image();
image.property_1 = "abcdefg";
it can't compile as the Flash builder says:
Description Resource Path Location Type
1119: Access of possibly undefined property jdkfjds through a reference with static type mx.controls:Image.
adm.mxml /adm/src Line 209 Flex Problem
How can I do that? Or I need to extends the Image class? It's quite boring.
Upvotes: 1
Views: 864
Reputation: 13327
Image
is not declared as dynamic class so you can`t dynamically add properties.
Derive from Image
and extend the class with the dynamic
keyword:
package mypackage
{
import mx.controls.Image;
public dynamic class DynamicImage extends Image {}
}
and now this will work:
import mypackage.DynamicImage;
var image:DynamicImage = new DynamicImage();
image.property_1 = "abcdefg";
Upvotes: 3
Reputation: 2503
If you know all the attributes you need to add and they won't change (often), this will work.
package mypackage
{
import mx.controls.Image;
public class ExtendedImage extends Image
{
public function ExtendedImage()
{
super();
}
//option 1
private var prop1:String = "";
public function get property_1():String
{
return prop1;
}
public function set property_1(val:String):void
{
prop1 = val;
}
//option 2
public var property_2:String = "";
}
}
Upvotes: 4
Reputation: 9897
But you can use container for your image and add extra properties there; or use dictionary with image as a key and property as a value.
Upvotes: 0