Accessing TabNavigator from child mxml :-Adobe AIR - apache-flex

This is my AIR application's UI structure::
Tab Navigater(Main UI)
-->child1.mxml
(toggle button bar)
|--element1.mxml
|--element2.mxml
|--element3.mxml
-->child2.mxml
(toggle button bar)
|--element1.mxml
|--element2.mxml
|--element3.mxml
-->child3.mxml
(toggle button bar)
|--element1.mxml
|--element2.mxml
|--element3.mxml
I want to access the parent element and change that index from child element and child of child element..Can you help me? or advice me.
Example:
I want to change the tab from the elemet2.mxml in child3.mxml

For encapsulation purposes you should never access a parent. The proper approach is to dispatch an event from the child and listen to it the parent. In your event listener method you can perform the parent functionality you desire.

You can not access directly.You can access through some frameworks or eventlistener.

Related

Broadcast event down to child tree in RactiveJS

I need fire event from parent component to childs components like broadcast method in AngularJS. How it possible in RactiveJS?
P.S: For example i have a tabs with different content includes components, when tabs renders only one tab active(visible) other tabs are hidden. When i select other tab it become active and show content. At this moment tab should send event refresh down to the childs component to let they know that they must initialize or refresh (because while it was hidden it couldn't initialized right).
Within the tab component, observe that the tab has become "active" and call refresh:
this.observe('active', function(active){
if(active){ control.refresh() }
})
Events don't fire down the hierarchy.
One option would be to put the template in a section watching a visible or rendered flag. Then set the flag to true when the tab becomes active. If there is something outside of the template that needs to be handled, you can observe it from your script.
Out of curiosity, what can't initialize correctly while it's hidden? Or do you mean not rendered, as there is no DOM to access? In that case, you may want to look into decorators.

Add child to parent component that is not visible in flex

I have a mxml file that extends a parent class. The parent has a component that is hidden initially and only shown once a button is pressed. I would like to add a new child component to this hidden component from my extended mxml. Is there a way to access the super component and add the child once the buton is pressed? Maybe listen to an event?
Right now i have a solution that solves the problem by loading the hidden components but it´s not a nice solution.
super.advancedOptionsSearchBox.getChildren();
super.advancedOptionsSearchBox.addChildAt(getEANContainer(), 1);
If i do not call the getChildren I get a index out of bounds exception on the call to addChildAt method since the array of children is empty in the hidden component.
Couldn't you just set property
creationPolicy="all"
to your component? That way it's created even if it's initially not visible.

Flex 4, multiple instances of a custom component listening the same event of a parent

In short:
I need an event listener in a custom component so all its instances (without editing them) react at the same time, fired by a dispatched event in its parent container.
In detail:
I have a custom component with Tab navigator. (The tabs are intended to show different preferences for different Languages.)
I have a button bar with buttons for all the languages.
There are a lot of instances of the custom component.
I want to click in a button of the languages bar and get ALL the instances switched to the same tab (the custom component contains the logic to change the tab).
I can do it by adding the event listener for EACH INSTANCE of the custom component, so it calls an internal function that changes the tab. But it seems to be very coupled, isn't it?
I wonder if it can be done in the master CLASS of the component, so it listen for events in its parent container, whichever it is.
In my mind this code shoud work, but it doesn´t (obviously ill'use a custom event to pass the new language value):
this.parent.addEventListener("lang_change", this.change_tab);
This way I can just drop an instance of the component, and see it working for itself.
Thank you in advance
I need an event listener in a custom
component so all its instances
(without editing them) react at the
same time, fired by a dispatched event
in its parent container.
The very thing you want to do, by definition, breaks encapsulation. In an ideal world, a component should know nothing of it's parent. If the component needs to communicate with it's parent, it should dispatch an event. IF a parent needs to communicate to children it should call a public method on that child (or change a public property). From an encapsulation stand point, I cannot recommend that the child listen for events on the parent.
I want to click in a button of the
languages bar and get ALL the
instances switched to the same tab
(the custom component contains the
logic to change the tab).
So, then put a click handler for the button and do something like this:
public function onClick():void{
myCustomTabNavigator1.selectedIndex = 1
myCustomTabNavigator2.selectedIndex = 1
myCustomTabNavigator2.selectedIndex = 1
}
You can also set the selectedItem if you a reference to it. , If you have your custom TabNavigators in an Array, you can loop over them. IF the custom TabNavigators are child of your custom component you can create a method in that custom component to set the defaults and call that method on each component instead of setting selectedIndex directly.
I think you should to use some MVC model like:
Cairngorm
http://code.google.com/p/swizframework/
http://www.robotlegs.org/
http://puremvc.org/

viewstack vs. tab navigator

I'm new to flex and was looking at some of the components that ship with flex.
Can someone tell me the difference between viewstack and tab navigator. They seem to be somewhat similar.
When do you use one or the other?
Both are navigator containers.
The difference is tabnavigator displays tabs (one for each of its child) in order to control which child should be displayed.
Viewstack doesn't have a UI which means you change the selected child with actionscript code.
Also, you can use a tabnavigator, a togglebuttonbar or other UI navigators as controllers for your viewstack by setting the navigator dataProvider property to the id of your viewstack.
both are same , but
in viewStack at a time any only one item can be selected in run time,while all are in a quee(not seems),
where as with tabNavigator all items are visible ,depending upon requirement we can select any one tab at a instance
Note : to show all options visible tab navigator is usefull,
to show only one among all items go for tab navigator
TabNavigator extends ViewStack and supplys some default UI to navigate to children of the TabNavigator.
Use TabNavigator when all you need is standard navigation (like main menu's on web sites).
Use ViewStack when you need custom navigation, like vertical lists, or when you dont need navigation (you might have a view stack with a login box and switch the view on login event)

Flex 4: Component move event

I have a CustomTextInput component based on TextInput (Spark) component. The instance of this class is placed on a popup window (TitleWindow).
How can I capture the popup move (dragging the title) event inside CustomTextInput implementation?
MoveEvent.MOVE event of the CustomTextInput itself doesn't work. Of course, I can't access the parent popup window inside the component implementation, because it's a common component that can be used not only on the popup windows.
Couldn't the parent title window notify the inner component? It would require making a custom TitleWindow component, but it seems the most logical way to implement this behavior.

Resources