Thinking about this some more, you can remove commitProperties if you
can determine the bounds some other way besides actually drawing.  For a
simple circle, the radius tells all and measure wouldn't call
getBounds() and just set measuredWIdth/Height to 2 * circleRadius +
borderThickness.  Then in updateDL, you would actually do the drawing
and use 1/2 the min of unscaledWidht/Height to determine the radius, or
draw an ellipse, or whatever you think is right.
 
If you are drawing something really complex, then I would draw it in
commitProperties so you can call getBounds during measure.  It sort of
depends on whether and how you plan to handling resizing and aspect
ratios.

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Jim Hayes
Sent: Thursday, January 17, 2008 8:05 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Drawn objects acting as children to
components?



Not quite sure exactly what you're looking for here Jason, but I'm
guessing it's something like this:
(I've just hacked at your last example since its very late here and I'm
tired, but hope it helps get you a bit further).
Note your component instance now has width+height set to 100% and
there's an override of updateDisplayList.
I'm actually really unhappy with the resultant code for a few reasons,
so please don't take it as an example of good practice in any way.
But, at the end of the day, your circle gets drawn in the middle of the
panel when the panel resizes, which I think is something along the lines
of what you wanted to do.

<mx:Panel id="networkBrowserPanel" width="100%" height="100%"
layout="absolute" title="Network" >
<c:NetworkLayout container="{networkBrowserPanel}" width="100%"
height="100%"
outerAlpha="1" innerAlpha="1" outerColor="#ffffff" innerColor="0x666666"
circleRadius="20" /> 
</mx:Panel> 

package components
{
import mx.core.UIComponent;
import flash.geom.Rectangle;

public class NetworkLayout extends UIComponent
{
public var container:UIComponent;
public var borderThickness:int;
public var outerColor:uint;
public var innerColor:uint;
public var outerAlpha:int;
public var innerAlpha:int;
public var circleRadius:int;

public function NetworkLayout()
{
super();
}

override protected function commitProperties():void
{
drawCircle();
}

private function drawCircle():void
{
graphics.clear();
var thisWidth:int = measuredWidth;
var thisHeight:int = measuredHeight;
var middleX:int = thisWidth/2;
var middleY:int = thisHeight/2;

graphics.lineStyle(borderThickness, outerColor, outerAlpha);
graphics.beginFill(innerColor, innerAlpha)
graphics.drawCircle(middleX, middleY, circleRadius); 
}

override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void 
{
super.updateDisplayList(unscaledWidth, unscaledHeight); 
measuredWidth = unscaledWidth;
measuredHeight = unscaledHeight; 
drawCircle();
}

override protected function measure():void
{
var rect:Rectangle = getBounds(container);
measuredWidth = rect.width;
measuredHeight = rect.height; 
}

}
}

-----Original Message-----
From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
on behalf of Merrill, Jason
Sent: Fri 18/01/2008 01:42
To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
Subject: RE: [flexcoders] Drawn objects acting as children to
components?

OK, thanks, I have knocked this down to it's simplest form. The graphic
appears in the right spot, but it does not respond to changes in the
panel's size change. I'm not sure how to implement that in my component.
I'm passing in a reference to the Panel container, but it's not
responding to it's width and height - I tried adding a listener to the
panel's updateComplete event, but when I reference the panel, I get an
error saying I cannot assign to a null property. I took that code out,
see the rest below:

<mx:Panel id="networkBrowserPanel" width="100%" height="100%"
layout="absolute" title="Network" >
<c:NetworkLayout container="{networkBrowserPanel}" 
outerAlpha="1" innerAlpha="1" outerColor="#ffffff"
innerColor="0x666666" circleRadius="20" />
</mx:Panel> 

package components
{
import mx.core.UIComponent;
import flash.geom.Rectangle;

public class NetworkLayout extends UIComponent
{
public var container:UIComponent;
public var borderThickness:int;
public var outerColor:uint;
public var innerColor:uint;
public var outerAlpha:int;
public var innerAlpha:int;
public var circleRadius:int;

public function NetworkLayout()
{
super();
}

override protected function commitProperties():void
{
drawCircle();
}

private function drawCircle():void
{
graphics.clear();
var thisWidth:int = measuredWidth;
var thisHeight:int = measuredHeight;
var middleX:int = thisWidth/2;
var middleY:int = thisHeight/2;
graphics.lineStyle(borderThickness, outerColor, outerAlpha);
graphics.beginFill(innerColor, innerAlpha)
graphics.drawCircle(middleX, middleY, circleRadius); 
}

override protected function measure():void
{
var rect:Rectangle = getBounds(container);
measuredWidth = rect.width;
measuredHeight = rect.height;
}

}
}


Jason Merrill 
Bank of America 
GT&O L&LD Solutions Design & Development 
eTools & Multimedia 

Bank of America Flash Platform Developer Community 

__________________________________________________________
This communication is from Primal Pictures Ltd., a company registered in
England and Wales with registration No. 02622298 and registered office:
4th Floor, Tennyson House, 159-165 Great Portland Street, London, W1W
5PA, UK. VAT registration No. 648874577.

This e-mail is confidential and may be privileged. It may be read,
copied and used only by the intended recipient. If you have received it
in error, please contact the sender immediately by return e-mail or by
telephoning +44(0)20 7637 1010. Please then delete the e-mail and do not
disclose its contents to any person.
This email has been scanned for Primal Pictures by the MessageLabs Email
Security System.
__________________________________________________________

 

Reply via email to