使用菜单的Flex组件生命周期 - 最佳实践

时间:2022-11-23 05:25:55

I have built a multiplage application in Flex with different user roles. I use a View Stack with a Menu Bar to navigate between the different pages.

我在Flex中构建了一个具有不同用户角色的多平台应用程序。我使用带有菜单栏的View Stack在不同页面之间导航。

However - each time a page gets opened, I need to do some database calls, apply User Role settings, etc. in an init() function. This init function may reference some UI elements of this page.

但是 - 每次打开页面时,我都需要在init()函数中执行一些数据库调用,应用用户角色设置等。此init函数可以引用此页面的某些UI元素。

I tried to load it with the "creationComplete" event, but this one gets only triggered once (since the page is not rebuilt each them the view stack shows it).

我尝试使用“creationComplete”事件加载它,但是这个只被触发一次(因为页面没有重建,视图堆栈显示它们)。

Now I have put it on the "show" event, but this seems not to get triggered consistently, or before the page is fully created the first time.

现在我把它放在“show”事件上,但这似乎不是一直触发,或者在第一次完全创建页面之前。

Whats the best practice for this case? * I have to pass in data * Call init functions (database calls) * Manipulate components

什么是这种情况的最佳做法? *我必须传入数据*调用init函数(数据库调用)*操作组件

Ideally I would need a way to call init each time the page is loaded and after all components are created.

理想情况下,我需要一种方法来在每次加载页面时以及在创建所有组件之后调用init。

Thanks for your help, Martin

谢谢你的帮助,马丁

3 个解决方案

#1


Just an idea but why not trying to do your remote call on ViewStack change effect. You could use an interface for this that your views implements.

只是一个想法,但为什么不尝试在ViewStack上进行远程调用更改效果。您可以使用视图实现的接口。

#2


Try updateComplete event.

尝试updateComplete事件。

Dispatched when an object has had its commitProperties(), measure(), and updateDisplayList() methods called (if needed).

在对象调用了commitProperties(),measure()和updateDisplayList()方法(如果需要)时调度。

This is the last opportunity to alter the component before it is displayed. All properties have been committed and the component has been measured and layed out.

这是在显示组件之前更改组件的最后机会。所有属性都已提交,组件已经过测量和布局。

#3


I had the same kind of problem when I wrapped the s:Group with wrapper class to put inside TabNavigator. The result, show event is not being called. Finally I changed all my s:Group with mx:Canvas, directly put them into TabNavigator(The same thing goes for ViewStack too). After that creationComplete event was called once and subsequent page visits call show of mx:Canvas

当我将包装类包装到TabNavigator中时,我遇到了同样的问题。结果,show事件没有被调用。最后我改变了所有的:用mx:Canvas组合,直接将它们放入TabNavigator(同样适用于ViewStack)。之后,createComplete事件被调用一次,后续页面访问调用show of mx:Canvas

#1


Just an idea but why not trying to do your remote call on ViewStack change effect. You could use an interface for this that your views implements.

只是一个想法,但为什么不尝试在ViewStack上进行远程调用更改效果。您可以使用视图实现的接口。

#2


Try updateComplete event.

尝试updateComplete事件。

Dispatched when an object has had its commitProperties(), measure(), and updateDisplayList() methods called (if needed).

在对象调用了commitProperties(),measure()和updateDisplayList()方法(如果需要)时调度。

This is the last opportunity to alter the component before it is displayed. All properties have been committed and the component has been measured and layed out.

这是在显示组件之前更改组件的最后机会。所有属性都已提交,组件已经过测量和布局。

#3


I had the same kind of problem when I wrapped the s:Group with wrapper class to put inside TabNavigator. The result, show event is not being called. Finally I changed all my s:Group with mx:Canvas, directly put them into TabNavigator(The same thing goes for ViewStack too). After that creationComplete event was called once and subsequent page visits call show of mx:Canvas

当我将包装类包装到TabNavigator中时,我遇到了同样的问题。结果,show事件没有被调用。最后我改变了所有的:用mx:Canvas组合,直接将它们放入TabNavigator(同样适用于ViewStack)。之后,createComplete事件被调用一次,后续页面访问调用show of mx:Canvas