You do NOT want to use rawChildren, stick with normal practices..
Sprite is too low level to add to a Flex container. You need to wrap it in a UIComponent. I don't have a real example, but it will be something like: var uic:UIComponent = new UIComponent(); uic.addChild(circle); this.addChild(uic) ENTERFRAME might work, it depends on what you want to happen. Flex handles frames differently that Flash might. What are you trying to do? Tracy Spratt, Lariat Services, development services available _____ From: [email protected] [mailto:[email protected]] On Behalf Of brad.bueche Sent: Sunday, April 05, 2009 9:42 PM To: [email protected] Subject: [flexcoders] Re: var circle:Sprite = new Sprite(); Not working Thanks Tracy, Nate! Ok, that worked, in that it got rid of the errors. But then I got a type conversion error about not being able to convert a Sprite to a UIComponent. So I read throught some blogs and found this rawchildren solution and using Shape too. So now I get a circle on the screen with no errors but the evenhandlers dont seem to be working. Here is what I have (below). I think I'm going to have to use a timer. I dont think that .ENTERRAME is going to work in Flex is it? Here is a nice example. I might take this route instead. http://www.fortegam <http://www.fortegames.com/games/CannonBall/CannonBallTest.html> es.com/games/CannonBall/CannonBallTest.html brad code follows........ *********************************************************** <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe. <http://www.adobe.com/2006/mxml> com/2006/mxml" layout="absolute" creationComplete="buildCircle()"> <mx:Script> <![CDATA[ import flash.display.*; import flash.events.Event; import flash.events.MouseEvent; public var circle:Shape = new Shape(); private function buildCircle():void{ circle.graphics.beginFill(0x990000); circle.graphics.drawCircle(50, 50, 50); circle.graphics.endFill(); circle.addEventListener(MouseEvent.CLICK, startAnimation); this.rawChildren.addChild(circle); } private function fadeCircle(event:Event):void{ circle.alpha -= .05; if (circle.alpha <= 0) { circle.removeEventListener(Event.ENTER_FRAME, fadeCircle); } } private function startAnimation(event:MouseEvent):void{ circle.addEventListener(Event.ENTER_FRAME, fadeCircle); } > </mx:Script> </mx:Application> --- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com, Nate Beck <n...@...> wrote: > > Tracy beat me to it... but I'm going to send my email as well :). > This is because your code isn't in an event handler. In MXML you can't have > "free-floating" script, just like in an ActionScript 3 class, you can't have > circle.graphics.beginFill(0x990000) outside of a method. > I recommend doing the following: > > Change your mx:Application tag to read as this: > <mx:Application xmlns:mx="http://www.adobe. <http://www.adobe.com/2006/mxml> com/2006/mxml" layout="absolute" > creationComplete="onReady()"> > > Then: > > <mx:Script> > <![CDATA[ > import flash.display.Sprite; > import flash.events.Event; > import flash.events.MouseEvent; > > private function onReady():void { > var circle:Sprite = new Sprite(); > circle.graphics.beginFill(0x990000); > circle.graphics.drawCircle(50, 50, 50); > circle.graphics.endFill(); > addChild(circle); > } > > ]]> > </mx:Script> > > > > On Sun, Apr 5, 2009 at 1:38 PM, brad.bueche <b...@...> wrote: > > > I'm at a loss here. I copied this code straight off the adobe site: > > > > > > http://livedocs. <http://livedocs.adobe.com/flex/3/html/help.html?content=05_Display_Programm ing_29.html> adobe.com/flex/3/html/help.html?content=05_Display_Programming_29.html > > > > And copied it write into a new mxml project (below) and Flex is throwing > > 1120 erorrs saying "circle is undefined". How can that be? > > > > ****************************************************************** > > <?xml version="1.0" encoding="utf-8"?> > > <mx:Application xmlns:mx="http://www.adobe. <http://www.adobe.com/2006/mxml> com/2006/mxml" > > layout="absolute"> > > <mx:Script> > > <![CDATA[ > > import flash.display.Sprite; > > import flash.events.Event; > > import flash.events.MouseEvent; > > > > var circle:Sprite = new Sprite(); > > circle.graphics.beginFill(0x990000); > > circle.graphics.drawCircle(50, 50, 50); > > circle.graphics.endFill(); > > addChild(circle); > > > > function fadeCircle(event:Event):void{ > > circle.alpha -= .05; > > > > if (circle.alpha <= 0){ > > circle.removeEventListener(Event.ENTER_FRAME, fadeCircle); > > } > > } > > > > function startAnimation(event:MouseEvent):void{ > > circle.addEventListener(Event.ENTER_FRAME, fadeCircle); > > } > > > > circle.addEventListener(MouseEvent.CLICK, startAnimation); > > > > ]]> > > </mx:Script> > > > > </mx:Application> > > > > > > > > > > -- > > Cheers, > Nate > ---------------------------------------- > http://blog. <http://blog.natebeck.net> natebeck.net >

