Reputation: 2663
I am trying to use a button in my init() method.
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Test"
creationComplete="init()">
Now when I try to do something with my button I get the error mentioned. I am assuming maybe it has not loaded yet?
function init():void{
myButton.thisorthat == makes the error.
}
*EDIT** The button is created in MXML btw Not that it matters, but this is for a flex mobile app.
Upvotes: 0
Views: 839
Reputation: 949
Actually it does matter. One thing about NavigatorContent (assuming your children are a subset of one of these types of containers) to remember along with their halo counterparts is they all have a content creation policy set to deferred - meaning it creates the parent most layer of the view / viewstack, but not it's children until the user has actually navigated to that particular child. One cheat is to set the policy to 'ALL', but the better way is to actually listen for the FlexEvent.CONTENT_CREATION_COMPLETE instead (this is broadcast from the child of the navigation container).
Eg:
<halo:ViewStack id="setupStack" width="100%" height="100%">
<api:FileSelector width="100%" height="100%" owner="{this}"
enumerationMode="{FileSystemEnumerationMode.DIRECTORIES_ONLY}"
hint="{networkDbAccessHint}" />
<!- this is valid, but not it's children until contentCreateComplete is fired -->
<api:DataImport width="100%" height="100%" owner="{this}" />
</halo:ViewStack>
Both 'FileSelector' and 'DataImport' broadcast the event (extends s:NavigatorContent).
Upvotes: 3