4 Replies Latest reply on Jun 29, 2008 10:25 PM by Gregory Lafrance

    Basic Flex/ AS3 questions

    SiHoop Level 1
      I have 2 questions about the code below:
      First, Why can I not use the code to create a Sprite on line 10 instead of the button on line 11?
      Second, why can I not create an eventListener on the object circle1 with the commented code on line 16?

      Thanks!

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application creationComplete="temp()" xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
      <![CDATA[
      private function temp():void{
      import flash.display.Sprite;
      import flash.events.MouseEvent;
      import mx.controls.*
      import flash.display.DisplayObject;
      //var circle1:Sprite = new Sprite();
      var circle1:Button = new Button();
      circle1.graphics.beginFill(0xFF0000);
      circle1.graphics.drawCircle(10, 10, 10);
      circle1.name = "circle1";
      canvas1.addChild(circle1);}
      //canvas1.circle1.addEventListener(MouseEvent.CLICK, traceName);
      private function traceName(event:MouseEvent):void {
      trace(event.target.name);
      }
      ]]>
      </mx:Script>
      <mx:Canvas x="166" y="128" width="332" height="300" id="canvas1" backgroundColor="#857C7C" label="zzz">
      <mx:VBox x="86" y="0" height="100%" width="153" id="hbox1" />
      </mx:Canvas>
      </mx:Application>