2010-09-16 37 views
1

我在我的應用程序中遇到flex狀態問題。我期待做的是創建應用程序,從服務器獲取用戶角色guest/user/superUser(基於用戶名和密碼),然後根據該信息設置狀態客戶端。我的.mxml類需要包含某些基於該狀態的圖形元素。我遇到了包含基於項目應用程序級定義的狀態的元素的問題。我試圖避免必須在需要它的每個.mxml文件中定義狀態。有沒有辦法讓全局的Flex 4狀態(用戶角色)?

我覺得這可能是我忽略的東西,或者有更好的方法來做到這一點。任何示例輸入都非常有幫助。

我知道,這將返回當前狀態

Application.application.currentState; 

,但我期待幾乎「填充」的

<mx:states> 
    <mx:State name="state1"/> 
</mx:states> 
每一個的.mxml文件從應用程序定義的狀態

回答

0

如果您正在尋找動態 - here是您的解決方案(前兩種狀態 - defaultbig - 都是adde d在編譯時。第三狀態Bang-a-Gong在運行時添加的):

private function init():void { 
    // Create a new state and give it a name. 
    var stateBang:State = new State(); 
    stateBang.name = 'Bang-a-Gong'; 

    // Set the overrides with an array of AddChild, AddItems, 
    // RemoveChild, SetEventHandler, SetProperty, and SetStyle 
    stateBang.overrides = 
     [ new SetProperty(btn, "label", "Bang-a-Gong"), 
      new SetProperty(btn, "height", "150"), 
      new SetProperty(btn, "width", "300"), 
      new SetStyle(btn, "fontSize", "22"), 
      new SetStyle(btn, "fontWeight", "bold"), 
      new SetStyle(btn, "color", "#FF0000") ]; 

    // Add our new state to the available states of this component. 
    this.states.push(stateBang); 

    // Just for kicks lets add a transition for this state. 
    var transition:Transition = new Transition(); 
    transition.toState = 'Bang-a-Gong'; 

    // Create a new transition effect. 
    var resize:Resize = new Resize(btn); 

    // Create an composite effect, either: Sequence or Parallel. 
    var sequence:Sequence = new Sequence(); 

    // Add our resize effect. 
    sequence.addChild(resize); 

    // now add our composition effect to the transition we created. 
    transition.effect = sequence; 

    // Push our new transition into the transitions array for this component. 
    this.transitions.push(transition); 
} 

在另一種情況下,如果我在正確的方式理解,你應該在主要應用程序中創建一些對象,並通過FlexGlobals.topLevelApplication從所有子組件訪問它。

如果您想更改子狀態,您應該將已定義狀態的實例作爲最小值在一個位置,然後將它們複製到子組件,但是如果它們都是自定義邏輯又有什麼意義?

所以,讓我知道,如果它有幫助。

+0

FlexGlobals.topLevelApplication.yourObject.isSuperuser == true – Eugene 2010-09-19 17:24:12

相關問題