我正在尝试修改一个图像,该图像是从字符串中生成的:
[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 = 0.5;
}
}
在inactiveElements数组中有一堆ImageIds(way_0,way_1,..),我正在尝试设置每个Image的alpha值。
<mx:Image source="{wZero}" id="way_0"/>
<mx:Image source="{wOne}" id="way_1"/>
使用跟踪我得到了正确的ImageId字符串,但是转换为Image失败。
TypeError:错误#1009:Der Zugriff auf eine Eigenschaft oder eine Methode eines null-Objektverweises ist nicht möglich。
答案 0 :(得分:1)
你需要:
Image(this[element]).alpha = 0.5;
String
永远不会成为Image
。该图片是this
String
element
对象的属性
如果此解决方案不起作用,请发布更多代码。