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: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of learner404
Sent: Friday, February 15, 2008 7:55 AM
To: [email protected]
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
<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