Apache – Flex 3: Is it possible to use a remote image as the icon for a LinkButton

apache-flexflex3

We are creating a LinkButton programmatically and would like to set it's icon to an image retrieved from the remote server rather than something embedded within the SWF. The .icon property expects a Class but I can't figure out how to create one equivalent to an @Embed but from a dynamically generated URLRequest or URL String.

var myImage:Image = new Image();
myImage.source = "http://www.domain.com/img/1234.png";
myImage.width = 16;
myImage.height = 16;
myImage.scaleContent = true;

var myButton:LinkButton = new LinkButton();
myButton.label = "Some text"

// This is what I'm trying to figure out.
myButton.setStyle("icon", ???)

I'm probably missing something obvious – I've tried passing in the URL and myImage separately but both throw errors. Stepping into the setStyle() method shows that the code is expecting a Class – so what do I pass in place of the ???

I can't embed the image itself because it's dynamic – the URL is different each time the software runs.

Thanks for any assistance!

Best Answer

Why not just set the buttonMode of a mx:Image to true then add a click event?

<mx:Image source="{imageSource}" buttonMode="true" click="action()" />

I'm not sure its possible without using an embedded images with a linkButton

This might be worth a read

Edit... in AS3:

var img:Image = new Image();
img.source = "...";
img.buttonMode = true;
img.addEventListenever(MouseEvent.CLICK, funcName);
Related Topic