K. Barresi
K. Barresi

Reputation: 1315

Attaching a Sprite With ActionScript3 Using Flex

So I'm using Flex to access some of the useful libraries included, but I don't want to deal with the MXML stuff. So I'm writing it all in pure AS3.

Basically, I'm loading the main AS3 class with this MXML:

<?xml version="1.0" encoding="utf-8"?>
<local:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:local="asset.*" />

Now from there, the AS3 takes over and does all its stuff. However, when I try to draw something to my main Canvas class (which just extends Application) by using the addChild() method, It throws this error:

Type Coercion failed: cannot convert MyObject to mx.core.IUIComponent.

I have also tried adding it directly to the Canvas object's stage, but it's null.

Any suggestions?

Upvotes: 1

Views: 94

Answers (1)

Barış Uşaklı
Barış Uşaklı

Reputation: 13532

You can wrap your object in a UIComponent assuming MyObject is a subclass of DisplayObject.

var uicomponent:UIComponent = new UIComponent(); 
uicomponent.addChild(yourObject);
canvas.addChild(uiComponent);

Upvotes: 4

Related Questions