有没有办法拥有全局 Flex 4 状态(用户角色)?

发布于 2024-09-20 00:08:10 字数 469 浏览 4 评论 0原文

我的应用程序中存在弹性状态问题。我想要做的是在应用程序创建完成后,从服务器获取用户角色 guest/user/superUser (基于用户名和密码),然后根据该信息设置状态客户端。我的 .mxml 类需要包含基于该状态的某些图形元素。我遇到了包含基于项目应用程序级别定义的状态的元素的问题。我试图避免在每个需要它的 .mxml 文件中定义状态。

我觉得这可能是我忽略的简单事情,或者也许有更好的方法来做到这一点。任何示例输入都非常有帮助。

我知道这会返回当前状态

Application.application.currentState;

,但我希望

<mx:states>
    <mx:State name="state1"/>
</mx:states>

从应用程序中定义的状态几乎“填充”每个 .mxml 文件

I am having an issue with flex states in my application. What I am looking to do is on creation complete of the application, obtain a user role guest/user/superUser (based on username and password) from a server, then set the state client side based on that information. My .mxml classes need to include certain graphic elements based on that state. I am running into the issues of including elements based on the states defined at the Application level of the project. I am trying to avoid having to define the states in each .mxml file that needs it.

I feel that this is possibly something easy that I am overlooking or maybe there is a better way to do this. Any examples input is very helpful.

I know that this returns the current state

Application.application.currentState;

but I am looking to almost "populate" the

<mx:states>
    <mx:State name="state1"/>
</mx:states>

of every .mxml file from the states defined in the Application

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年慕年 2024-09-27 00:08:10

如果您正在寻找动态状态 - 这里就是您的解决方案(前两个状态 - defaultbig - 在编译时添加。第三个状态 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 );
}

在另一种情况下,如果我理解正确,您应该在 ma​​in 应用程序中创建一些对象,并通过 FlexGlobals.topLevelApplication 从所有子组件访问它。

如果你想改变子组件的状态,你应该在一个地方有一些已经定义了最小状态的实例,然后将它们复制到子组件,但是如果它们都是自定义逻辑,那有什么意义呢?

所以,如果有帮助的话,请告诉我。

If you are looking for dynamic states - here is your solution (The first two states – default and big - are added at compile time. The third state Bang-a-Gong is added at runtime):

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 );
}

In another case, if I understood in right way, you should create some Object in main application, and access it from all child components via FlexGlobals.topLevelApplication.

If you want to change child states, you should have some instance with already defined states as minimum in one place, and later copy them, to child components, but what sense if they are all custom logic?

So, let me know, if it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文