Add child to parent component that is not visible in flex - apache-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.

Related

Accessing TabNavigator from child mxml :-Adobe AIR

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.

How to completely initialise a component but not add it to the display? Flex

I need to completely initialize a custom component in my Flex app (i.e. I should be able to access it from action script and get its properties and its children etc), But I do not want to add it to the display or make it visible.
I have tried to add it to my visible component, but keep it visible, but often many of its properties are set only when it is drawn, so i don't get what i need.
Is there a way to add a custom component to some sort of 'Virtual' display, that is not visible to the user?
You could add the component to an invisible Sprite - that way the component itself could both be on the stage and have its own visible property set to true.
Did you try using initialize()? After a view is added to the display list, the initialization stage begins. Calling initialize() before addChild() should let you initialize the view without needing to first add it to the stage.
For more info visit:
http://flexscript.wordpress.com/2008/10/24/flex-component-lifecycle-and-flex-component-framework/
http://blog.deadinkvinyl.com/2008/10/05/flex-3-addchild-and-initialize/
Not sure if possible without adding it to the display list, although I'd wish it were to some extent.
I once had to make custom drag proxy, which didn't work with the real component, because of some weird skinning issues. So instead I had PopupMananger add a box as a popup, added my component to the box, called validateNow on the component, drew it in a bitmap data, removed the popup, and used the bitmap data as the proxy.
So what you were trying was missing a call to validateNow most likely.

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/

Is it possible to call a function in a parent component from a child component in Flex?

I need to call a function located in the parent component and make the call from the child component in Flex 3. Is there a way to access functions in the parent component from the child component? I know I can dispatch an event in the child and add a listener in the parent to call the function, but just wanted to know if could also directly call a parent function from a child. Thanks
You can use parentApplication
For example... if i have a main.mxml that calls a component we'll call child.mxml, i can call functions in main from within child by doing the following:
parentApplication.parentsFunctionName(parameters);

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