You can try:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Script>
<![CDATA[
function drawStuff()
{
var ref_mc = pad.createEmptyObject("square", getNextHighestDepth());
ref_mc.fillRect(0, 0, 200, 200, 0x000000, 100);
}
]]>
</mx:Script>
<mx:Canvas id="pad" width="400" height="300" />
<mx:Button label="Draw" click="drawStuff();" />
</mx:Application>
If you didn't want the overhead of UIObject being instantiated, you could
create a movie clip, and do fillRect instead, like:
var ref_mc = pad.createEmptyMovieClip("square", getNextHighestDepth());
pad.fillRect.call(ref_mc, 0, 0, 200, 200, 0x000000, 100);
----- Original Message -----
From: "vaykent2" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, June 11, 2005 5:21 PM
Subject: [flexcoders] Why can't I draw in the Canvas component using
fillRect?
(or - another possible subject line - 'What is the quickest, least
processor intensive way of 'putting' 'squares' on a component?')
In the end I'm finding that createChild(VBox, ...) is just too
intensive. It takes too long. I'm looking for a better way... a
drawing API-ish way might be what I want...
I'd like to be able to populate a canvas with a score (100-200) of
filled rectangles at some point _after_ the application is up and
running... but when I reference the canvas and use the method fillRect
it doesn't work (ie. I can't see any change at all - and yes, the fill
color is different from the background color of the canvas where the
items are being created).
A lot of the examples that I've seen run drawing methods during the
init handler of the component - I need to be able to draw and erase
the 'stage' of the component after it's been instantiated...
Any ideas? I've tried calling draw and redraw right after the call to
fillRect, but those don't seem to work either.
I'm thinking of something like (this isn't the actual code):
<mx:Application...
<mx:Script>
<![CDATA[
function drawRect(event){
display.fillRect(0,0,100,100,0xFF0000,100);
}
]]>
</mx:Script>
<mx:Canvas id="display"...
<mx:Button click="drawRect" />
</mx:Application>
Yahoo! Groups Links
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/