In general, when we write a code that inherits from the flex component and adds subcomponents to it, and then wants to add subcomponents to the label and so on, how to solve this problem, the custom component codes are as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <mx:canvas xmlns:mx= "Http://www.adobe.com/2006/mxml" Width= "height=" > <mx:Metadata> [Defaultproperty ("Children")] </mx:Metadata> <mx:Script> <! [cdata[ private var _children:array = []; private var _childrenchanged:boolean = false; Public function set Children (value:*): void { If (value is Displayobject) _children = [value]; Else _children = value; _childrenchanged = true; Invalidateproperties (); } Public function Get Children (): Array { return _children; } protected override function Commitproperties (): void { Super.commitproperties (); if (_childrenchanged) { For each (Var child:displayobject in _children) { Contentbox.addchild (child); } } } ]]> </mx:Script> <mx:canvas id= "Contentbox" Width= "100%" height= "100%"/> </mx:Canvas> |
This article comes from the "Simple and Easy" blog, so be sure to keep this source http://dengshuangfu.blog.51cto.com/8794650/1588730
Custom Flex Components Add subcomponents using labels