开发者

cast String to Image Id to modify in flex

i'm trying to modify a image, which is casted from a String:

[Embed(source='map.swf', symbol='wZero')]
[Bindable]
private var wZero:Class;

[Embed(source='map.swf', symbol='wOne')]
[Bindable]
private var wOne:Class;

public function setInactiveElements () : void {
    trace ("setInactiveElements called");
    inactiveElements : Array = mapMan.getInactiveElements();
    for each ( var element : String in inactiveElements ) {
        trace ("inactiveElement: " + element );
        Image(element).alpha = 0.5;
                // also tried: 
                (element as Image).alpha 开发者_如何学JAVA=  0.5;
    }
}

In the inactiveElements Array are a bunch of ImageIds (way_0, way_1,..) and i'm trying to set the alpha-value of each Image.

<mx:Image source="{wZero}" id="way_0"/>
<mx:Image source="{wOne}" id="way_1"/>

with the trace i got the right String of ImageId but the cast to Image fails.

TypeError: Error #1009: Der Zugriff auf eine Eigenschaft oder eine Methode eines null-Objektverweises ist nicht möglich.


You need:

Image(this[element]).alpha = 0.5;

A String can never become an Image. The image is a property of of the this object keyed on the String element


If this solution doesn't work, please post more of your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜