0 Replies Latest reply on Mar 31, 2010 1:31 PM by southlondon

    dynamically add Canvas not working

    southlondon Level 1

      I have extended the Canvas class and i am trying to add it dynamically  to the stage, unfortunately it is not showing up.

      code from extended Canvas class;

      package com
      {
      import mx.containers.Canvas;

      public class CustomCanvas extends Canvas
      {
      public function CustomCanvas()
      {
      super();
      }

      protected override function updateDisplayList(unscaledWidth:Number,  unscaledHeight:Number):void
      {
      super.updateDisplayList(unscaledWidth, unscaledHeight);

      super.setStyle("borderStyle","solid");
      super.setStyle("cornerRadius",10);
      super.setStyle("backgroundColor","#FFFFFF");
      }

      }
      }

      Here is the Flex code that is being used to initiate the Canvas;

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
      xmlns:mx="http://www.adobe.com/2006/mxml"
      layout="absolute"
      cornerRadius="20"     

      creationComplete="init()" xmlns:com="com.*">


      <mx:Script>
      <![CDATA[
      import mx.flash.UIMovieClip;
      import mx.core.UIComponent;

      import mx.containers.Canvas;
      import com.CustomCanvas;          

      public function init():void
      {

      var myCanvas:CustomCanvas = new CustomCanvas();
      addChild(myCanvas);
      myCanvas.x = 600;
      myCanvas.y = 200;
      myCanvas.width = 200;
      myCanvas.height = 200;
      }     

      ]]>

      </mx:Script>

      <com:CustomCanvas
      width="200"
      height="200"
      borderStyle="solid"
      cornerRadius="10"
      backgroundColor="#FFFFFF">

      </com:CustomCanvas>







      </mx:Application>


      Creating the Custom Canvas class via MXML works fine, but trying to  create it dynamically does not.

      Any thoughts ?