문제

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