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.fortegames.com/games/CannonBall/CannonBallTest.html

brad
code follows........
***********************************************************
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.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 [email protected], 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.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.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.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.natebeck.net
>


Reply via email to