简体   繁体   中英

Set Property of a Control on a Different State? - Flex 4

I'm having trouble setting the property of a control on another state.

Latest_News_Display is under the Latest_News state. I want to set Latest_News_Display 's x property even if the currentState is set to Intro . However, when I try to use Latest_News.Latest_News_Display.x = 10 ,it returns an error that says 1120: Access of undefined property Latest_News . So how do I go about doing it?

There is no guarantee a component in another state has been created at the time you are trying to set it. It's hard to say for sure without seeing your code, but I'm guessing that is the issue based on your error.

You'll, basically, have to create your own method of deferred value setting. So, when you try to set it do something like this:

if(Latest_News_Display){
 Latest_News_Display.x = 10
} else {
 cachedLatest_News_DisplayX = 10
}

Then listen to the currentStateChange event and set the new value then:

protected function onCurrentStateChange(event:StateChangeEvent):void{    
Latest_News_Display.x = cachedLatest_News_DisplayX 
}

I'll also add that, based on the bolded items in your question that it appears you are trying to access a state by name Latest_News. If you create a local variable pointed at a specific state, you can do this. But, if you're using MXML then you probably didn't. Even so, a state is just, basically, an array of overrides you wouldn't be able to access components in that state directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM