Flex 4: Component move event - apache-flex

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.

Related

Context Menu of TableView in Child Widget

I am programming in C++ in QT and trying to make a UI with dynamic tabs having tables inside each of them. For doing the same, I had my TabWidget in the main window, and another widget with just the tableView. As the tabs are dynamically being added to the main window by a button click, I make a new object of my widget and put it in that.
I also have another version of the application in which there are no tabs, just a tableView in the main window.
I am unable to open the context menu in the former case, while it works perfectly for the latter.
I am using the signal "customContextMenuRequested" in both the cases. Don't understand what I need to add for it to work when the tableView is in a child widget.
Some help please?
Thanks already!
Did you check that nothing is involving QAbstractScrollArea, it's possible that in this case it would signal/slot as expected.
This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. The position pos is the position of the context menu event that the widget receives. Normally this is in widget coordinates. The exception to this rule is QAbstractScrollArea and its subclasses that map the context menu event to coordinates of the viewport() .

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.

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.

keydown event reusable code - how can I write it once and use anywhere in my flex application

I am new to flex framework.
I have created an application using flex framework 4.1 which is having various components that are shown to the end user in the form of a popup window using <mx:TitleWindow>.
This titlewindow is closed either on the click of the close button (displayed in it's titlebar) or by pressing the "escape key" on the keyboard.
I coded a functionality wherein I close the current TitleWindow whenever an 'escape' button is pressed.
Here is what I did.
On the keydown event of TitleWindow I called this function
private function detectescapekeypress(event:KeyboardEvent):void
{
if(event.charCode == Keyboard.ESCAPE)
PopUpManager.removePopUp(this);
}
But this function does not work when I define it in the main home screen of my application and call it using parentApplication.detectescapekeypress(event) on the keydown event of TitleWindow
I had to repeat this code for every TitleWindow that I have used in the project.
How can I write the above functionality only once and reuse it amongst various TitleWindow and other components so that the code for the same is not repeated across various components?
Note: Every TitleWindow that I am using has different code, scripts and layout in it.
Thanks
Why don't u just extend the TitleWindow component and add that functionality to your new custom component? Then use it everywhere instead of the original TitleWindow.
I assume u're using at least SDK 4.1
Create a new mxml file called for example CustomTitleWindow.mxml and paste the following
http://www.copypastecode.com/68211/
Then change all your title windows to CustomTitleWindow.
P.S. Note that in order for the key event to be dispatched, the component must have focus.
blz

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/

Resources