Flex AS3: Assign a button's upSkin property with a remote file dynamically?

Posted by Aaron on Stack Overflow See other posts from Stack Overflow or by Aaron
Published on 2010-03-18T08:16:37Z Indexed on 2010/03/18 8:21 UTC
Read the original article Hit count: 505

Filed under:
|

I am building a Flex application with ActionScript 3. Unfortunately I've hit a wall with this one...

I would like to be able to apply an upSkin to my dynamically generated button like this:

//this theSkin variable is dynamic in my app, but for this example it's a simple string
var theSkin:String = "http://www.mypicturedomain.com/images/myimage.gif";

var navBtn:Button = new Button();
navBtn.id = "thumb1";
navBtn.width = 60;
navBtn.height = 45;    

//skin the button
navBtn.setStyle("upSkin", theSkin);

//add the button to my canvas
myCanvas.addChild(navBtn);

When I attempt this, I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@3dac941 to Class.

How do I skin this button with my image dynamically? A couple of things to consider:

  1. The upSkin image must be remote. It can't be local.
  2. The button must be generated dynamically (it's in a for loop).

Any help/ideas would be much appreciated at this point!

© Stack Overflow or respective owner

Flex AS3: Assign a button's upSkin property with a remote file dynamically?

Posted by aaron.lovelace on Stack Overflow See other posts from Stack Overflow or by aaron.lovelace
Published on 2010-03-18T08:08:32Z Indexed on 2010/03/18 8:11 UTC
Read the original article Hit count: 505

Filed under:
|

I am building a Flex application with ActionScript 3. Unfortunately I've hit a wall with this one...

I would like to be able to apply an upSkin to my dynamically generated button like this:

//this theSkin variable is dynamic in my app, but for this example it's a simple string
var theSkin:String = "http://www.mypicturedomain.com/images/myimage.gif";

var navBtn:Button = new Button();
navBtn.id = "thumb1";
navBtn.width = 60;
navBtn.height = 45;    

//skin the button
navBtn.setStyle("upSkin", theSkin);

//add the button to my canvas
myCanvas.addChild(navBtn);

When I attempt this, I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@3dac941 to Class.

How do I skin this button with my image dynamically? A couple of things to consider:

  1. The upSkin image must be remote. It can't be local.
  2. The button must be generated dynamically (it's in a for loop).

Any help/ideas would be much appreciated at this point!

© Stack Overflow or respective owner

Related posts about flex

Related posts about actionscript-3