Adobe Air: Null pointers when rendering takes time

2019-09-02 02:24发布

I am using the a ViewStack controlled with visibility of selected NavigatorContent being dependent on user selection of an option from a drop down menu.

enter image description here

Each View of the ViewStack has its own separate UI elements including 2-3 DataGrid, charts etc - think of it as a simple school application where each view binds to a course and shows performance of students for that course (while listing students in grid)

Sometimes, there is a problem with showing the data though - before the Rendering completes, the data is ready to be populated; this throws a null exception as the UI element where the data needs to be populated has not been created yet.

For this, I made the 'creationPolicy' set to 'all'. All works just fine after this property is set. But there certainly are tonnes of performance issues:-

  1. Even if the user never ever visits beyond the 1st visible view, the other views do get rendered (UI elements initialized and created).
  2. Performance hit at startup - startup time is large and grows with the number of views I have (right now I have 9 views with creationPolicy set to all)!! Application was quick to load when only the 1st view was visible by default and creationPolicy was set to default/auto
  3. UI kind of hangs/becomes unresponsive while application starts (as it all happens in the same thread)

What could be a possible solution to this.

These are the solutions that I had in mind, and which didn't work for a reason or two:-

  • For the first time a view is selected via the dropdown controller (i.e. when the rendering cum UI creation is yet to take place), I can show a preloader or sometime. I tried doing this, but the UI still hangs/becomes unresponsive.
  • CallLater can it help? Not really, as I would still be creating all views even if they are not required.

So, I need an elegant way of displaying the views (and show some sort of progress or loader) when they are created/instantiated.

Update

I get the Null errors when there is a sort of race condition - when the processing (which returns data to be filled into UI components, lets say a grid) completes before the rendering of the UI element completes - I have recognized why it happens. Initially, I had creationPolicy set to default, so whenever I use to select a view, it was created at that time; and in case the data to be populated was returned before the elements of the view were created there were null pointer (as the UI element I use to refer to were still be created and thus were null at that instance). Now I am being forced to set the creationPolicy to all so that UI is created for all views and I fire the data processing on selection of that view from the dropdown.

What I'd rather like to do is to have a way to create the UI on demand (and not all of the UI even if it is not being used).

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-02 02:51

I would suggest you use modules instead of view stack.

When modules are used separate swf files are created, and not loaded when the application is loaded. A module file is loaded only when it is called through moduleloader.load(module) method.

查看更多
太酷不给撩
3楼-- · 2019-09-02 03:09

Maybe you shouldn't have the data processing push the results, but vice-versa, have the UI pull the data from the model once the UI controls are ready?

For example, have the data reside in ArrayCollections that you bind to DataGrids. That way, it doesn't matter who finishes first. Data generator doesn't even have to know who or where displays it, and the UI will show the data as soon as ArrayCollection signals that the data has changed.

查看更多
登录 后发表回答