Flex 应用程序先加载数据
我有一个 Flex 应用程序,它从后端数据库获取数据,然后在 3 个视图之一中显示内容。 这些视图都位于在 main.mxml 中实例化的视图堆栈中 获取数据(远程对象)的方法也在main.mxml中。
视图依赖于数据,所以我如何才能确保在创建/初始化视图堆栈中的任何视图之前首先加载数据以阻止出现空引用错误?
I have a flex app that takes data from a back end database then displays the content in one of 3 views.
These views are all in a viewstack which is instantiated in main.mxml
The method to get the data (remote object)is also in main.mxml.
The views rely on the data so how can I go about making sure that the data is loaded first before any of the views in viewstack are created / initialised to stop me having null reference errors?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您获取数据时,您应该定义一个回调函数来接收该数据(回调函数是您放入 addEventListener 中的函数)。您只需在调用所有回调后调用该函数即可创建视图堆栈。
我的方法是创建一个名为 numCallbacks 的类字段。每次调用回调之一时都会增加此变量。在增加它之后,立即检查 numCallbacks == 您拥有的回调数。如果为 true,则创建您的视图堆栈。
When you get the data, you should have a callback function defined to receive that data (callback function is the function you put into addEventListener). You just need to call the function to create your viewstack after all your callbacks have been called.
The way I would do it is create an class field called numCallbacks. Increment this variable everytime one of your callbacks is called. Right after you increment it, check if numCallbacks == the number of callbacks you have. If true, create your view stack.