On Fri, Feb 15, 2008 at 2:47 PM, Merrill, Jason < [EMAIL PROTECTED]> wrote:
""" And to draw a Rectangle, why are you using beginBitmapFill? Just try beginFill instead. """ Oops, I went to quickly with the completion, thanks Jason. """ You need to add the sprite to a container of some kind like a canvas or a panel. """ What would be the best way to do that In my code above? My attempts have failed so far, the last one (I added a canvas in the mxml and try to add the shape rectangle to it): 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: """ 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); return rectAndCircle; } }//class }//package """ I've got an error 1034 (BTW if anyone know how i can avoid to localise the AS3 error messages so I can paste full error messages in English) Thanks francois You need to add the sprite to a container of some kind like a canvas or a > panel. > > And to draw a Rectangle, why are you using beginBitmapFill? Just try > beginFill instead. > > > Jason Merrill > *Bank of America * > GT&O L&LD Solutions Design & Development > eTools & Multimedia > > *Bank of America Flash Platform Developer Community* > > > > > ------------------------------ > *From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On > Behalf Of *learner404 > *Sent:* Friday, February 15, 2008 7:55 AM > *To:* flexcoders@yahoogroups.com > *Subject:* [flexcoders] draw simple shapes in a Flex app? > > Hi guys, > > I'm new at Flex3/AS3 and I'm already stuck at what I thought would be a > simple "hello world" script: > > GOAL: > A flex app with a button. When the button is hit it a simple shape > (rectangle) would appear to the screen. > > PROPOSAL (doesn't work): > > 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(); > } > ]]> > </mx:Script> > <mx:Button label="draw" click="drawNow()"></mx:Button> > </mx:Application> > """ > DrawApp.as: > """ > package { > > import flash.display.*; > > class DrawApp extends Sprite > { > public function DrawApp() > { > var rectAndCircle:Shape=new Shape(); > rectAndCircle.graphics.lineStyle(1); > rectAndCircle.graphics.beginBitmapFill(0x0000FF,1); > rectAndCircle.graphics.drawRect(125,0,150,75); > addChild(rectAndCircle); > } > } > > } > """ > When I compile this in FB3 I've got 1067 error codes beginning with > rectAndCircle.graphics.beginBitmapFill(0x0000FF,1); > > Any idea what I'm missing here? > > Thanks > > francois > > > >