There is no call to super.updateDisplayList, so the SWFLoader doesn't get a chance to run its sizing code on the content.
In theory, you shouldn't have needed to copy this much code. Subclassing Image and overriding updateDisplayList and adding new things should be enough. ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of tobydeh Sent: Tuesday, March 20, 2007 6:42 AM To: [email protected] Subject: [flexcomponents] Re: Extended Image rounded corners etc size problems. Sorry guys I forgot to add the code.... package com.tmgc.view.components { import flash.display.DisplayObject; import flash.events.Event; import mx.controls.listClasses.BaseListData; import mx.controls.listClasses.IDropInListItemRenderer; import mx.controls.listClasses.IListItemRenderer; import mx.core.IDataRenderer; import mx.core.mx_internal; import mx.events.FlexEvent; import mx.controls.SWFLoader; import flash.geom.Rectangle; import flash.display.Bitmap; import mx.graphics.BitmapFill; import flash.display.Sprite; import flash.display.Graphics; import mx.graphics.RectangularDropShadow; import mx.controls.Alert; use namespace mx_internal; //-------------------------------------- // Events //-------------------------------------- /** * Dispatched when the <code>data</code> property changes. * * <p>When you use a component as an item renderer, * the <code>data</code> property contains the data to display. * You can listen for this event and update the component * when the <code>data</code> property changes.</p> * * @eventType mx.events.FlexEvent.DATA_CHANGE */ [Event(name="dataChange", type="mx.events.FlexEvent")] //-------------------------------------- // Other metadata //-------------------------------------- [DefaultBindingProperty(source="progress", destination="source")] [DefaultTriggerEvent("complete")] [IconFile("Image.png")] [Style(name="showDropShadow", type="Boolean", inherit="no")] [Style(name="strokeClr", type="uint", inherit="no")] [Style(name="stroke", type="Number", inherit="no")] [Style(name="cornerRadius", type="Number", inherit="no")] [Style(name="cornerRadiusTopLeft", type="Number", inherit="no")] [Style(name="cornerRadiusTopRight", type="Number", inherit="no")] [Style(name="cornerRadiusBottomLeft", type="Number", inherit="no")] [Style(name="cornerRadiusBottomRight", type="Number", inherit="no")] public class RoundedImage extends SWFLoader implements IDataRenderer, IDropInListItemRenderer,IListItemRenderer { //---------------------------------------------------------- // // Constructor // //---------------------------------------------------------- /** * Constructor. */ public function RoundedImage() { super(); // images are generally not interactive tabChildren = false; tabEnabled = true; super.scaleContent = this.scaleContent; showInAutomationHierarchy = true; } //---------------------------------------------------------- // // Variables // //---------------------------------------------------------- /** * @private */ private var makeContentVisible:Boolean = false; /** * @private * Flag that will block default data/listData behavior */ private var sourceSet:Boolean; //---------------------------------------------------------- // // Overridden properties // //---------------------------------------------------------- //---------------------------------- // source //---------------------------------- [Bindable("sourceChanged")] [Inspectable(category="General", defaultValue="", format="File")] /** * @private */ override public function set source(value:Object):void { sourceSet = true; super.source = value; } //---------------------------------------------------------- // // Properties // //---------------------------------------------------------- //---------------------------------- // data //---------------------------------- /** * @private * Storage for the data property. */ private var _data:Object; [Bindable("dataChange")] [Inspectable(environment="none")] /** * The <code>data</code> property lets you pass a value to the component * when you use it in an item renderer or item editor. * You typically use data binding to bind a field of the <code>data</code> * property to a property of this component. * * <p>When you use the control as a drop-in item renderer, Flex * will use the <code>listData.label</code> property, if it exists, * as the value of the <code>source</code> property of this control, or * use the <code>data</code> property as the <code>source</code> property.</p> * * @default null * @see mx.core.IDataRenderer */ public function get data():Object { return _data; } /** * @private */ public function set data(value:Object):void { _data = value; if (!sourceSet) { source = listData ? listData.label : data; sourceSet = false; } dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE)); } //---------------------------------- // listData //---------------------------------- /** * @private * Storage for the listData property. */ private var _listData:BaseListData; [Bindable("dataChange")] [Inspectable(environment="none")] /** * When a component is used as a drop-in item renderer or drop-in * item editor, Flex initializes the <code>listData</code> property * of the component with the appropriate data from the List control. * The component can then use the <code>listData</code> property * to initialize the other properties of the drop-in * item renderer * * <p>You do not set this property in MXML or ActionScript; * Flex sets it when the component is used as a drop-in item renderer * or drop-in item editor.</p> * * @default null * @see mx.controls.listClasses.IDropInListItemRenderer */ public function get listData():BaseListData { return _listData; } /** * @private */ public function set listData(value:BaseListData):void { _listData = value; } //---------------------------------------------------------- // // Inherited methods: UIComponent // //---------------------------------------------------------- /** * @private */ override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { var rc:Rectangle = new Rectangle(); var image:Bitmap = Bitmap(content); var f:BitmapFill = new BitmapFill(); var fillArea:Sprite = new Sprite(); this.addChild(fillArea); var g:Graphics = fillArea.graphics; var o:Number = 0; var showDrpShdw:Boolean = getStyle("showDropShadow"); var cornerRadius:Number = getStyle("cornerRadius"); var strokeWidth:Number = getStyle("stroke"); var strokeColor:uint = getStyle("strokeClr"); var cTL:Number = getStyle("cornerRadiusTopLeft"); var cTR:Number = getStyle("cornerRadiusTopRight"); var cBL:Number = getStyle("cornerRadiusBottomLeft"); var cBR:Number = getStyle("cornerRadiusBottomRight"); g.clear(); if(isNaN(cornerRadius)) cornerRadius = 0; if(isNaN(cTL)) cTL = cornerRadius; if(isNaN(cTR)) cTR= cornerRadius; if(isNaN(cBL)) cBL = cornerRadius; if(isNaN(cBR)) cBR = cornerRadius; // Shadow if (showDrpShdw) { var dropShadow:RectangularDropShadow = new RectangularDropShadow(); dropShadow.distance = 5; dropShadow.angle = 45; dropShadow.color = 0; dropShadow.alpha = 0.4; dropShadow.tlRadius = cornerRadius; dropShadow.trRadius = cornerRadius; dropShadow.blRadius = cornerRadius; dropShadow.brRadius = cornerRadius; dropShadow.drawShadow(g, 0, 0, unscaledWidth, unscaledHeight); } g.lineStyle(strokeWidth,strokeColor,1); if(f != null) { rc.left = o; rc.right = o; rc.width = unscaledWidth; rc.height = unscaledHeight; f.begin(g,rc); } g.drawRoundRectComplex(o,o,unscaledWidth,unscaledHeight,cTL,cTR,cBL,cBR) ; if(f != null) { f.end(g); } } //---------------------------------------------------------- // // Inherited event handlers: SWFLoader // //---------------------------------------------------------- /** * @private */ override mx_internal function contentLoaderInfo_completeEventHandler(event:Event):void { var obj:DisplayObject = DisplayObject(event.target.loader); super.contentLoaderInfo_completeEventHandler(event); // Hide the object until draw obj.visible = false; makeContentVisible = true; invalidateDisplayList(); } } }
