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!

有帮助吗?

解决方案 2

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);

其他提示

It's kind of hard to tell from your question but, if you want to set a default icon if NO DisplayObject is passed, just check if icon is null in the MyMarker constructor, eg:

...
public function MyMarker(icon:DisplayObject=null) {
    if (icon==null) {
    // set default icon here...

    }

    }
...

As for the inheritance issue, so long as the object passed inherits from DisplayObject, you should be fine. You may run into trouble if you try to invoke methods on the object that don't appear in DisplayObject.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top