does actionscript addChild require a display object first

Posted by touB on Stack Overflow See other posts from Stack Overflow or by touB
Published on 2010-03-19T16:49:30Z Indexed on 2010/03/19 16:51 UTC
Read the original article Hit count: 387

Filed under:
|
|
|

I'm trying to move away from mxml to actionsctipt. I have a <s:Rect> that I've created and set its properties, but having trouble adding it.

var aRect:Rect = new Rect();
//set properties like aRect.x, aRect.y, aRect.width, aRect.height

//tried adding it various ways
addChild(aRect);
Application.addChild(aRect);
Application.application.addChild(aRect);
stage.addChild(aRect);

But I keep getting the error 1067: Implicit coercion of a value of type spark.primitives:Rect to an unrelated type flash.display:DisplayObject

Originally in the mxml, it was right inside <s:Application> not nested inside anything

<s:Application>

    <s:Rect id="aRect" x="10" y="10" width="15%" height="15%">
         //then fill code here, removed for readability
    </s:Rect>

</s:Application>

What's the deal, I thought actionscript would be nicer than mxml.

© Stack Overflow or respective owner

Related posts about flex

Related posts about actionscript