1 Reply Latest reply on Feb 15, 2008 9:39 AM by schneo

    Draw a rectangle from a flex app

    schneo
      Hello,

      GRAND CHALLENGE (should be "hello world" that anyone should easily find):

      1) - a flex app with a button
      2) - when clicked the button draw the rectangle

      PROPOSED NON WORKING SOLUTION:

      draw.mxml:

      """
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>import DrawApp;</mx:Script>
      <mx:Script>
      <![CDATA[
      function drawNow():void{
      var myRectangle:DrawApp = new DrawApp();
      myCanvas.addChild(myRectangle.returnRectangle());
      }
      ]]>
      </mx:Script>
      <mx:Canvas width="100%" height="100%" id="myCanvas"></mx:Canvas>
      <mx:Button label="draw" click="drawNow()"></mx:Button>
      </mx:Application>
      """
      DrawApp.as:
      """
      // ActionScript file

      package {

      import flash.display.*;

      class DrawApp extends Sprite
      {
      public function DrawApp()
      {
      //don't use the constructor anymore since it won't return the rectangle
      }
      public function returnRectangle():Shape
      {
      var rectAndCircle:Shape=new Shape();
      rectAndCircle.graphics.lineStyle(1);
      rectAndCircle.graphics.beginFill(0x0000FF,1);
      rectAndCircle.graphics.drawRect(125,0,550,575);
      rectAndCircle.graphics.endFill();
      return rectAndCircle;
      }
      }//class

      }//package
      """
      I've got an error "1034" (BTW as a bonus if anyone know how i can avoid to have the localized AS3 error messages so I can paste full error messages in English)

      CHALLENGE:
      Can someone show me how to make this wok before Silverlight2 Beta get out?

      Thanks from francois who's mad trying to solve this "should be obvious hello world" for too long and who also discovered lately:
      - the lack of threads in AS3
      - the insane security policy around Flash Player (must install a proxy to access a public API...)
      - etc.

      Help please Oo