That error is often caused by attempting to initialize a complex variable
outside of a function.  This is because of the way mxml files are generated
into classes.

 

Declare the circle variable in instance scope as you have, but do the
initialization in a function called by creationComplete.

 

Tracy Spratt,

Lariat Services, development services available

  _____  

From: [email protected] [mailto:[email protected]] On
Behalf Of brad.bueche
Sent: Sunday, April 05, 2009 4:39 PM
To: [email protected]
Subject: [flexcoders] var circle:Sprite = new Sprite(); Not working

 

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>



Reply via email to