Search code examples
actionscript-3apache-flex

Flex4: how to create the view states in as class (code-behind)


According to this document from Adobe Create and apply view states is <s:State/> a state object. How to create the view states in code-behind ActionScript class?


Solution

  • I have found a simple solution, and I don't have to declare the states using skinning architecture. I don't even to declare the states in my ApplicationClass which extends WindowedApplication. The solution is: declare the states only in the Main.MXML and by all means with the right namespace, in my case it should be "custom". Here is the Main.MXML:

    <?xml version="1.0" encoding="utf-8"?>
    <custom:ApplicationClass xmlns:fx="http://ns.adobe.com/mxml/2009"
                             xmlns:s="library://ns.adobe.com/flex/spark"
                             xmlns:mx="library://ns.adobe.com/flex/mx"
                             xmlns:custom="components.*">
        <custom:states>  
            <s:State name="loginState"/> 
            <s:State name="infoState"/>
        </custom:states>
    
        <s:Panel id="loginPanel" title="Login" includeIn="loginState" />
    
    </custom:ApplicationClass>
    

    I only want to change between different Panels, so this method works well for me. There are certainly other cases, in which the states need to be declared in skinning. I have got this solution form this link: Error: Could not resolve to a component implementation.