Custom Component Example
http://stackoverflow.com/questions/3237048/flex-as3-changing-width-height-doesnt-affect-contents
/**
* Copyright 9re ( http://wonderfl.net/user/9re )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1oNx
*/
package {
import flash.geom.Point;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Sprite;
import mx.events.ResizeEvent;
import spark.core.SpriteVisualElement;
/**
http://stackoverflow.com/questions/3237048/flex-as3-changing-width-height-doesnt-affect-contents
*/
public class FlashTest extends SpriteVisualElement {
public function FlashTest() {
var testSprite:SpriteVisualElement = new SpriteVisualElement();
var childSprite:MySpriteVisualElement = new MySpriteVisualElement();
childSprite.width = 200;
childSprite.height = 100;
childSprite.name = "child";
testSprite.addChild(childSprite);
addChild(testSprite);
testSprite.addEventListener(MouseEvent.CLICK, grow);
}
public function grow(event:MouseEvent):void
{
event.target.width += 5;
event.target.height += 5;
trace(event.target, " grow", event.target.width);
}
}
}
import mx.core.UIComponent;
import spark.core.SpriteVisualElement;
internal class MySpriteVisualElement extends SpriteVisualElement {
override protected function invalidateParentSizeAndDisplayList():void {
super.invalidateParentSizeAndDisplayList();
updateDisplayList();
}
protected function updateDisplayList():void
{
graphics.clear();
graphics.beginFill(0xFFFF00, 1);
graphics.drawRect(0, 0, width, height);
graphics.endFill();
}
}