3 Replies Latest reply on Jun 11, 2008 10:36 PM by Gregory Lafrance

    Vector graphics & animation using Flex

    kstart
      Hi,

      I want to draw a vector graphics in flex 3 then later on I need to do some animation on it. But I encounter some problem and I cannot solve it and I get this error message "1120: Access of undefined property circle". Thanks... Here is the code:

      <mx:Script>
      <![CDATA[
      import flash.display.*;

      private var circle:Shape = new Shape()
      var xPos:Number = 100;
      var yPos:Number = 100;
      var radius:Number = 50;

      circle.graphics.beginFill(0xFF8800);
      circle.graphics.drawCircle(xPos, yPos, radius);
      addChild(circle);

      ]]>
      </mx:Script>
        • 1. Re: Vector graphics &amp; animation using Flex
          Gregory Lafrance Level 6
          You can declare and initialize variables in a <script> tag outside a function, but manipulating them must be done in a function. In this case, having a function for the creationComplete, or perhaps the initialize events works well.

          Also, you can't add shapes by themselves to the app, you must wrap them in a UIComponent.

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init()">
          <mx:Script>
          <![CDATA[
          import mx.core.UIComponent;
          import flash.display.*;

          private var circle:Shape = new Shape();

          private function init():void{
          var xPos:Number = 100;
          var yPos:Number = 100;
          var radius:Number = 50;

          circle.graphics.beginFill(0xFF8800);
          circle.graphics.drawCircle(xPos, yPos, radius);
          var comp:UIComponent = new UIComponent();
          comp.addChild(circle);
          addChild(comp);
          }
          ]]>
          </mx:Script>
          </mx:Application>
          • 2. Re: Vector graphics &amp; animation using Flex
            kstart Level 1
            hi Greg Lafrance

            Thank for reply. I learn something new. So each time I create a object I just put the object into the container is it? Like

            Animation must put into MovieClip container?
            What does "UIComponent" mean?
            • 3. Re: Vector graphics &amp; animation using Flex
              Gregory Lafrance Level 6
              When writing actionscript inside <script> tags, there are some things that you can do outside functions, and some things that can only be done inside functions.

              You can declare and initialize variables in a <script> tag outside a function, but manipulating them must be done in a function. In this case, having a function for the creationComplete, or perhaps the initialize events works well.

              Also, you can't add shapes by themselves to the app, you must wrap them in a UIComponent.

              By this I mean that you can't just add a graphic to the Flex app display list. There are other ways to do it, but you can wrap the graphic in a UIComponent, which is a class that can be added to the Flex 3 display list.