Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does actionscript addChild require a display object first

Solution:

if you have the same problem, addElement() instead of addChild() is what did it


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.

like image 210
touB Avatar asked Mar 19 '10 16:03

touB


1 Answers

tried changing addChild(aRect); to addElement(aRect); and that worked beautifully.

like image 174
touB Avatar answered Sep 18 '22 08:09

touB