Search code examples
actionscriptflash-buildermxml

Trying to access an images .source information in actionscript - for some reason it doesn't show up


I'm working on a project (using flash builder 4.5) where a user can click on one of a number of pictures to perform an action. The images are all loaded into an array of UIComponents through actionscript.

I have a private variable as follows:

private var _selectedChild:UIComponent;

Which keeps track of which UIComponent is currently "selected" (was the last item clicked).

I just want to show an Alert when the picture is clicked displaying it's id and the source filename.

Alert.show("Current id: " + _selectedChild.id + " -- filename: " + _selectedChild.source);

The id comes out easy with _selectedChild.id, but there is no such thing as .source - I looked throughout the entire list of possible variables eclipse gives me and I can't figure out which one would display the url or the source. I feel like I might be missing something easy - does anyone know how to get this information from a UIComponent?

This is the relevant 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>

Any help is much appreciated.


Solution

  • If I understand your code correctly, you need to cast the UIComponent to an Image first:

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