Package | mx.states |
Class | public class AddChild |
Inheritance | AddChild ![]() |
Implements | IOverride |
overrides
property of the State class.
Use the creationPolicy
property to specify to create the child
at application startup or when you change to a view state.
The child does not dispatch the creationComplete
event until
it is added to a container. For example, the following code adds a
Button control as part of a view state change:
<mx:AddChild relativeTo="{v1}"> <mx:Button id="b0" label="New Button"/> </mx:AddChild>
In the previous example, the Button control does not dispatch
the creationComplete
event until you change state and the
Button control is added to a container.
If the AddChild class defines both the Button and a container, such as a Canvas container,
then the Button control dispatches the creationComplete event when it is created.
For example, if the creationPolicy
property is set to all
,
the Button control dispatches the event at application startup.
If the creationPolicy
property is set to auto
,
the Button control dispatches the event when you change to the view state.
The <mx:AddChild>
tag
has the following attributes:
<mx:AddChild Properties target="null" targetFactory="null" creationPolicy="auto" position="lastChild" relativeTo="parent of the State object" />
Default MXML PropertytargetFactory
See also
Property | Defined By | ||
---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | |
creationPolicy : String
The creation policy for this child. | AddChild | ||
position : String
The position of the child in the display list, relative to the
object specified by the relativeTo property. | AddChild | ||
![]() | prototype : Object [static]
A reference to the prototype object of a class or function object. | Object | |
relativeTo : UIComponent
The object relative to which the child is added. | AddChild | ||
target : DisplayObject
The child to be added. | AddChild | ||
targetFactory : IDeferredInstance
The factory that creates the child. | AddChild |
Method | Defined By | ||
---|---|---|---|
Constructor. | AddChild | ||
Applies the override. | AddChild | ||
Creates the child instance from the factory. | AddChild | ||
![]() |
Indicates whether an object has a specified property defined. | Object | |
Initializes the override. | AddChild | ||
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | |
![]() |
Indicates whether the specified property exists and is enumerable. | Object | |
Removes the override. | AddChild | ||
![]() |
Sets the availability of a dynamic property for loop operations. | Object | |
![]() |
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | |
![]() |
Returns the string representation of the specified object. | Object | |
![]() |
Returns the primitive value of the specified object. | Object |
creationPolicy | property |
creationPolicy:String
The creation policy for this child.
This property determines when the targetFactory
will create
the instance of the child.
Flex uses this properthy only if you specify a targetFactory
property.
The following values are valid:
Value | Meaning |
---|---|
auto | (default)Create the instance the first time it is needed. |
all | Create the instance when the application started up. |
none | Do not automatically create the instance.
You must call the createInstance() method to create
the instance. |
The default value is "auto".
public function get creationPolicy():String
public function set creationPolicy(value:String):void
position | property |
public var position:String
The position of the child in the display list, relative to the
object specified by the relativeTo
property.
Valid values are "before"
, "after"
,
"firstChild"
, and "lastChild"
.
The default value is "lastChild".
relativeTo | property |
public var relativeTo:UIComponent
The object relative to which the child is added. This property is used
in conjunction with the position
property.
This property is optional; if
you omit it, Flex uses the immediate parent of the State
object, that is, the component that has the states
property, or <mx:states>
tag that specifies the State
object.
target | property |
target:DisplayObject
The child to be added.
If you set this property, the child instance is created at app startup.
Setting this property is equivalent to setting a targetFactory
property with a creationPolicy
of "all"
.
Do not set this property if you set the targetFactory
property.
public function get target():DisplayObject
public function set target(value:DisplayObject):void
targetFactory | property |
targetFactory:IDeferredInstance
The factory that creates the child. You can specify either of the following items:
If you set this property, the child is instantiated at the time
determined by the creationPolicy
property.
Do not set this property if you set the target
property.
This propety is the AddChild
class default property.
Setting this property with a creationPolicy
of "all"
is equivalent to setting a target
property.
public function get targetFactory():IDeferredInstance
public function set targetFactory(value:IDeferredInstance):void
AddChild | () | Constructor |
public function AddChild(relativeTo:UIComponent = null, target:DisplayObject = null, position:String = "lastChild")
Constructor.
ParametersrelativeTo:UIComponent (default = null ) — The component relative to which child is added.
| |
target:DisplayObject (default = null ) — The child object.
All Flex components are subclasses of the DisplayObject class.
| |
position:String (default = "lastChild ") — the location in the display list of the target
relative to the relativeTo component. Must be one of the following:
"firstChild", "lastChild", "before" or "after".
|
apply | () | method |
public function apply(parent:UIComponent):void
Applies the override. Flex retains the original value, so that it can
restore the value later in the remove()
method.
This method is called automatically when the state is entered. It should not be called directly.
Parameters
parent:UIComponent — The parent of the state object containing this override.
The override should use this as its target if an explicit target was
not specified.
|
createInstance | () | method |
public function createInstance():void
Creates the child instance from the factory.
You must use this method only if you specify a targetFactory
property and a creationPolicy
value of "none"
.
Flex automatically calls this method if the creationPolicy
property value is "auto"
or "all"
.
If you call this method multiple times, the child instance is
created only on the first call.
initialize | () | method |
public function initialize():void
Initializes the override.
Flex calls this method before the first call to the
apply()
method, so you put one-time initialization
code for the override in this method.
Flex calls this method automatically when the state is entered. It should not be called directly.
remove | () | method |
public function remove(parent:UIComponent):void
Removes the override. The value remembered in the apply()
method is restored.
This method is called automatically when the state is entered. It should not be called directly.
Parameters
parent:UIComponent — The parent of the state object containing this override.
The override should use this as its target if an explicit target was
not specified.
|
<?xml version="1.0" ?> <!-- Simple example to demonstrate the States class. --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <!-- Define one view state, in addition to the base state.--> <mx:states> <mx:State name="Register"> <mx:AddChild relativeTo="{loginForm}" position="lastChild"> <mx:target> <mx:FormItem id="confirm" label="Confirm:"> <mx:TextInput/> </mx:FormItem> </mx:target> </mx:AddChild> <mx:SetProperty target="{loginPanel}" name="title" value="Register"/> <mx:SetProperty target="{loginButton}" name="label" value="Register"/> <mx:SetStyle target="{loginButton}" name="color" value="blue"/> <mx:RemoveChild target="{registerLink}"/> <mx:AddChild relativeTo="{spacer1}" position="before"> <mx:target> <mx:LinkButton id="loginLink" label="Return to Login" click="currentState=''"/> </mx:target> </mx:AddChild> </mx:State> </mx:states> <!-- Define a Panel container that defines the login form.--> <mx:Panel title="Login" id="loginPanel" horizontalScrollPolicy="off" verticalScrollPolicy="off" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"> <mx:Text width="100%" color="blue" text="Click the 'Need to Register?' link to change state. Click the 'Return to Login' link to return to the base state."/> <mx:Form id="loginForm" > <mx:FormItem label="Username:"> <mx:TextInput/> </mx:FormItem> <mx:FormItem label="Password:"> <mx:TextInput/> </mx:FormItem> </mx:Form> <mx:ControlBar> <mx:LinkButton id="registerLink" label="Need to Register?" click="currentState='Register'"/> <mx:Spacer width="100%" id="spacer1"/> <mx:Button label="Login" id="loginButton"/> </mx:ControlBar> </mx:Panel> </mx:Application>