正在尝试访问actionscript中的images.source信息-由于某些原因,它没有';我没有出现

正在尝试访问actionscript中的images.source信息-由于某些原因,它没有';我没有出现,actionscript,flash-builder,mxml,Actionscript,Flash Builder,Mxml,我正在做一个项目(使用flash builder 4.5),用户可以单击多张图片中的一张来执行操作。图像都通过actionscript加载到UIComponents数组中 我有一个私有变量,如下所示: private var _selectedChild:UIComponent; 跟踪当前“选中”的UIComponent(是最后单击的项目) 我只想在单击图片时显示一个警报,显示其id和源文件名 Alert.show("Current id: " + _selectedChild.id + "

我正在做一个项目(使用flash builder 4.5),用户可以单击多张图片中的一张来执行操作。图像都通过actionscript加载到UIComponents数组中

我有一个私有变量,如下所示:

private var _selectedChild:UIComponent;
跟踪当前“选中”的UIComponent(是最后单击的项目)

我只想在单击图片时显示一个警报,显示其id和源文件名

Alert.show("Current id: " + _selectedChild.id + " -- filename: " + _selectedChild.source);
id很容易用_selectedChild.id显示出来,但是没有.source这样的东西-我查看了eclipse提供给我的所有可能变量列表,我不知道哪一个会显示url或源。我觉得我可能错过了一些简单的东西——有人知道如何从UIComponent获取这些信息吗

这是相关的mxml:

<dp:Test id="test" width="100%" height="100%" >
        <mx:Image id="i1" source="images/i1.jpg"/>
        <mx:Image id="i2" source="images/i2.jpg"/>
    </dp:Test>


非常感谢您的帮助。

如果我正确理解了您的代码,您需要首先将UIComponent转换为映像:

var image:Image = _selectedChild as Image;
if (!image) trace("Nothing selected or the child is not an image");
Alert.show("Current id: " + image.id + " -- filename: " + image.source);

如果我正确理解您的代码,您需要首先将UIComponent强制转换为映像:

var image:Image = _selectedChild as Image;
if (!image) trace("Nothing selected or the child is not an image");
Alert.show("Current id: " + image.id + " -- filename: " + image.source);

您正在将mx:Image对象强制转换到基本UIComponent,该组件没有属性“source”。要么将_selectedChild保留为不明确的、*、类型,要么将其定义为mx.controls.Image。如果切换到spark,请使用spark.components.Image

或者,为了安全起见,在使用不明确类型时,可以基于属性执行检查:

if(_selectedChild.hasOwnProperty("source"))
{
    // do stuff
}

您正在将mx:Image对象强制转换到基本UIComponent,该组件没有属性“source”。要么将_selectedChild保留为不明确的、*、类型,要么将其定义为mx.controls.Image。如果切换到spark,请使用spark.components.Image

或者,为了安全起见,在使用不明确类型时,可以基于属性执行检查:

if(_selectedChild.hasOwnProperty("source"))
{
    // do stuff
}

谢谢我是flex新手,这对我帮助很大。谢谢!我是flex新手,这对我帮助很大。