Solutions for component inaccessible in flex multi-State (scenario)

Source: Internet
Author: User

Cause Analysis: After Flex creates multiple States (scenarios), only the components in the main State (scenario) are checked by default, and the components created in other states are not redirected to this State (scenario) previously unavailable [html] <? Xml version = "1.0" encoding = "UTF-8"?> <S: Application xmlns: fx =" http://ns.adobe.com/mxml/2009 "Xmlns: s =" library: // ns.adobe.com/flex/spark "xmlns: mx =" library: // ns.adobe.com/flex/mx "minWidth =" 955 "minHeight =" 600 "creationComplete =" init () "> <fx: Script> <! [CDATA [function init (): void {// unable to access the component myText that exists in the scenario "State2. text = "NotFound";} protected function btn_clickHandler (event: MouseEvent): void {// TODO Auto-generated method stub}]> </fx: Script> <s: layout> <s: BasicLayout/> </s: layout> <s: states> <s: State name = "State1"/> <s: state name = "State2"/> </s: states> <fx: Declarations> <! -- Place non-visual elements (such as services and value objects) Here --> </fx: Declarations> <s: button x = "135" y = "228" label = "Button" id = "btn" click. state2 = "btn_clickHandler (event)"/> <! -- MyText exists in State2 --> <s: TextInput includeIn = "State2" x = "134" y = "175" id = "myText"/> </s: application> solution: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <S: Application xmlns: fx =" http://ns.adobe.com/mxml/2009 "Xmlns: s =" library: // ns.adobe.com/flex/spark "xmlns: mx =" library: // ns.adobe.com/flex/mx "minWidth =" 955 "minHeight =" 600 "creationComplete =" init () "> <fx: Script> <! [CDATA [import mx. events. *; function init (): void {// Add the Scene Change listener in the home scene this. addEventListener (StateChangeEvent. CURRENT_STATE_CHANGE, stateChange);} function stateChange (event: StateChangeEvent): void {// when the scenario (State) jumps to "State2", the Operation component if (event. newState = "State2") {myText. text = "OK" ;}} protected function btn_clickHandler (event: MouseEvent): void {currentState = "State2" ;}]] ></fx: Script> <s: layout> <s: BasicLay Out/> </s: layout> <s: states> <s: State name = "State1"/> <s: State name = "State2"/> </s: states> <fx: Declarations> <! -- Place non-visual elements (such as services and value objects) Here --> </fx: Declarations> <s: button x = "135" y = "228" label = "Button" id = "btn" click = "btn_clickHandler (event)"/> <! -- MyText exists in State2 --> <s: TextInput includeIn = "State2" x = "134" y = "175" id = "myText"/> </s: application>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.