Search code examples
actionscript-3flashapache-flexactionscriptria

Actionscript: How to set an Image/Icon to a DisplayObject?


Now there is a Constructor: MyMarker(icon:DisplayObject=null) which accepts any DisplayObject, if I create a new instance of MyMarker(just new MyMarker()),it will be dsplayed with a default Icon,so how to set a Image/Icon into this Constructor? Any ideas are much appreciated!


Solution

  • You should create an appropriate DisplayObject in advance and then pass the reference to this object in the constructor:

    var myLittleCustomIcon:Sprite = new Sprite();
    myLittleCustomIcon.graphics.beginFill(0x00FF00, 1);
    myLittleCustomIcon.graphics.drawRect(0, 0, 100, 50);
    myLittleCustomIcon.graphics.endFill();
    var myCustomMaker:MyMarker = new MyMarker(myLittleCustomIcon);