How can I make sure all the components, even those that are not going to be visible at the beginning, load right away when I start my application?
I have an application with a ViewStack whose visible child is set via a sidebar menu. Say the ViewStack has two children, A and B. A is initially visible, whereas B is not. How can I make sure they both load at the beginning, so that when I change to B I don't have to wait for it to load?
each of your viewstacks should have
creationPolicy = "all";
not sure if this can be set at the application level or not to control all children, but I know it works on viewstacks.
Related
Is there a way to refresh a component or an application back to its initial state? I have an accordion navigator that stays on the most recently selected index even if I log out. Right now, my log out function takes me back to the login page which is at state(1). If I log back in and go into the accordion, it is on the last tab I had viewed.
I would like to be able to clear any data from the controls inside the nav and reset the nav back to its default. I thought something like,
public function logout():void{
currentState = "NotLoggedIn"
myAccordion.initialize(); }
would work but nothing happens. This is done in Flex 4.
I know I can make a huge loop clearing each control individually and setting the selectedIndex of the accordion to 0. I was hoping for a simpler solution.
It depends what you mean by "State".
If you have implemented states in your Flex Component, you can revert back to a previous state using:
component.currentState = 'myInitialState';
If you are not talking about states, explicitly, but rather about the internal values of the properties of the component, then Flex does not keep a history of those property values. You can keep track of them yourself and reset them in the manually.
Once you do that, your component will be, effectively, in the initial state.
I have created a custom item renderer for the tree, i have added some children in create children function, my problem is that sometimes i need to show these children and sometimes i don't, depending on clicking on a button which also i have added at create children, the problem is that i had to create the item even if i don't want it to be visible, and removed it by making visible false, and this costs a lot of memory, i have tried to create it at buttons click listener but when scrolling the child disappears, and it may appear again if i keep scrolling up and down..
i am trying to add the child just when i need it to be visible, is this possible or i have to create it on child creation method?
Typically you do something like this with states. This way the components within the container (in this case your item renderer) are only created when the container enters the given state. The nice thing about taking this approach is that you can remain oblivious to when components need to be created/removed and let the states model handle that for you. Hope that helps.
I have a Flex application with three different views. Only one view is shown at a time, and the choice of view depends on what part of the application the user is working with. If it had been an ordinary HTML webapp I would have created three different HTML-templates/pages for each view.
What is the recommended way to handle such application views in Flex?
The behavior you want is usually accomplished by using a ViewStack component. In MXML you declare child containers for each view you want, but only one gets shown at a time. You can change which one is shown programmatically whenever conditions are met by setting selectedIndex on your ViewStack. By default the first child container is displayed when run. Another approach is to declare and use states in your container and change currentState whenever you need to change the view. Hope that helps.
The situation: I've got a ViewStack with 2 children (both of type Panel).
The application starts with child 1 as the SelectedChild.
With a click on a button, child 2 is the SelectedChild. After that, I return to child 1 being the SelectedChild.
When I click Show Redraw Regions in the Flash Player, I can see child 2 being redrawn the whole time (i've got some moving objects in child 2). How can I prevent this from happening? Or can this only be done with actually removing the invisible (in this case child 2) child?
Why I want to achieve this? Child 2 will contain pretty much data (flv's, images, etc.) and when it's being cached like what happens now, it will slow down my application.
A major source of inefficiency in Flash can come from invisible objects on your display list. Not only do they continue to cause redraw region refreshes ("red rectangles"), they impose CPU penalties on Flash processing whenever the player needs to traverse the display list tree. Mouseovers are notably more expensive, even if you don't have any MouseEvent listeners, when the display list is larger. Any display list containing more than a couple thousand objects can start to feel the pain.
Long story short, sometimes performance dictates that you write your own "visibility manager" to swap objects in and out of the parent hierarchy as an alternative to toggling DisplayObject.visible.
I've figured it out: the only way seems to actually remove the child, or it's moving/animated content.
Calling video.stop(), animation.stop() like Amarghosh mentioned should help too.
I'm having some troubles with Flex with regards to changing controls on different viewstack panels. At runtime, certain controls aren't accessible and come back as null. Here's an example structure:
viewstack1
canvasPeople
datagridPeople
canvasDetails
tabNavigator1
canvasPersonDetail
txtLastname
canvasPersonOptions
comboboxOccupation
I have a "click" handler in datagrid1 set up to activate canvasB (viewstack1.selectedChild = canvasB) and the detail options box (tabNavigator1.selectedChild = canvasPersonOptions). The former works OK but the latter returns an error about accessing a null object, because at the moment the user clicks on an item in the People datagrid, the tabNavigator1 is null, as is any control underneath it. (its parent, though (canvasDetails), is addressable.) Currently this is a tiny application, so it's not like it's waiting to load the items. Is there a way to control how Flex renders controls so they're accessible before the user sees them? I don't know if this is specific to the viewStack control.
Yes, this is referred to as "creation policy" and it's a property on all Container classes. To do what you we're looking for, you can use a creation policy of "all"; "auto" is the default.
A creationPolicy of ContainerCreationPolicy.AUTO means that the container delays creating some or all descendants until they are needed, a process which is known as deferred instantiation. This policy produces the best startup time because fewer UIComponents are created initially. However, this introduces navigation delays when a user navigates to other parts of the application for the first time. Navigator containers such as Accordion, TabNavigator, and ViewStack implement the ContainerCreationPolicy.AUTO policy by creating all their children immediately, but wait to create the deeper descendants of a child until it becomes the selected child of the navigator container.
A creationPolicy of ContainerCreationPolicy.ALL means that the navigator containers immediately create deeper descendants for each child, rather than waiting until that child is selected. For single-view containers such as a VBox container, there is no difference between the ContainerCreationPolicy.AUTO and ContainerCreationPolicy.ALL policies.
More info here:
http://livedocs.adobe.com/flex/3/html/layoutperformance_04.html
Be careful with this though: Flex picked AUTO as the default for a reason. If your app grows large, the initialization time under creationPolicy=all will be large.
The creation of subcomponents is controlled by the creationPolicy property. It is described in detail in the Flex 3 documentation page "About the creationPolicy property".
If you set the property to "all", every subcomponent of the ViewStack container will be created as soon as the ViewStack is created. The same works for the TabNavigator. Of course this might have some performance implications, which are also described in the documentation.