Please help. I want to add a click event on checkbox that i created dynamically so that i know what checkbox I click.
Heres my code on action script:
var myCheckbox:CheckBox = new CheckBox();
vbox.addChild(myCheckbox);
How to add click event on checkbox?
private function myCheckboxClicked(event:MouseEvent)
{
// doStuff();
}
...
myCheckbox.addEventListener(MouseEvent.CLICK, myCheckboxClicked);
As long as it inherits EventDispatcher, you can attach a listener and it'll send events as normal.
Related
I'd like to avoid that mouse events triggered by the user don't get dispatched to their target objects, effectively "freezing" the GUI for the user.
In a sample application featuring just a single mx.controls.Button I called addEventListener on the button to get notified of mouse events. In the event handler, I called Event::stopImmediatePropagation on the event, assuming that this would "discard" the event. Clicking the button would call my event handler, but yet the button was "clicked" (it animated and triggered an event).
How could I do this?
button.mouseEnabled = false;
button.mouseChildren = false;
should work
Depending on how advanced your interface is, you could just throw an object (s:Rect in an s:Group would work) on top of everything, set width and height to 100%, and disable mouseChildren
USE removeEventListener()
var b:Button = new Button();
function init():void
{
b.addEventListener(MouseEvent.CLICK, onButtonClick);
}
function onButtonClick(event:MourseEvent):void
{
b.removeEventListener(MouseEvent.CLICK, onButtonClick);
}
I am writing a flex application and I have two Spark TextAreas. I want to create an EventListener so that when the user clicks on a text area, the text inside the TextArea is cleared:
this.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
private function onFocusIn(ev:FocusEvent):void {
if (this._showsCaption) {
this._showsCaption = false;
super.text = "";
}
}
Currently I can implement this with a Spark TextInput, but when I click on the TextArea, the focusIn event never fires and the onFocusIn() handler is never called.
Any thoughts would be much appreciated.
When you are extending the TextArea (as in your case), you can override the protected "focusInHandler" method. This is the handler that is called when the control gets focus. The same goes for the "focusOutHandler" method.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/UIComponent.html#focusInHandler()
I know how can I skip steps programmatically but I need "Skip" button too.
If you wish to add a new button to the wizard control then you will need to replace the existing Templates by creating custom
WizardStepNavigationTemplates(this is the template which is responsible for the controls which are displayed when on any normal wizard step)
WizardStartNavigationTemplate(this is the template which is responsible for the controls which are displayed when on the FIRST step of the wizard) and
WizardFinishNavigationTemplate (this is the template which is responsible for the controls which are displayed when on the Last step of the wizard)
internal class CustomWizardStartNavigationTemplate : CustomWizardNavigationTemplateBase
{
#region ITemplate Members
public CustomWizardStartNavigationTemplate(WizardDisplayConfig wizardDisplayConfig):base(wizardDisplayConfig){ }
/// <summary>
/// this overrides the method to define the navigation controls which will appear in the template.
/// Literal control is used to put spacing between the controls.
/// </summary>
public override void InstantiateIn(Control container)
{
Literal spacingliteral = new Literal();
spacingliteral.Text += " ";
Button btnSkip = new Button();
Button btnSave= new Button();
Button btnNext= new Button();
container.Controls.Add(btnSave);
container.Controls.Add(spacingliteral);
container.Controls.Add(btnNext);
container.Controls.Add(spacingliteral);
container.Controls.Add(btnSkip);
}
#endregion
}
Something like below is a sample implementation of how you can achieve the desired results. Note that by creating these new templates you will need to add button click events etc which i have not shown in my example. This is so when user clicks the button they will be moved to the next step etc.Hope this helps.
cheers
Niall
I've got a class that extends EventDispatcher.
What I want to do is to dispatch the click event when the component is clicked. (The class is essentially some text in a textfield that needs to be able to do certain things, and it needs to be able to respond to a click). Sounds easy enough... I want the event dispatched when that portion of the text is clicked. But uh...how? it's not like a button where I can just go
myButton.addEventListener(MouseEvent.CLICK, myClickHandler);
That's clear, because some component is going to be listening for the Click event dispatched when myButton is clicked. It is built into the AS3 framework that a button knows how to listen for a click event.
After the import statements I've got:
[Event(name="click" type="mx.events.Event")]
How do I dispatch the event when the component is clicked, when the component doesn't yet know how to respond to a click event? I've tried adding an event listener in the textfield which contains this custom class of text, but nothing's happening because the Click event hasn't been dispatched.
You can create your own click event and dispatch it. You can do that also to dispatch clicks on objects where no user ever have clicked :D
Try this:
var mEvent:MouseEvent = new MouseEvent(MouseEvent.CLICK, [HERE MORE PARAMS BY YOU]);
yourObject.dispatchEvent(mEvent);
Now, you will recieve Click Events from yourObject.
Let's say your class consists TextField tf. Then public function YourClass():void { //Constructor
{
//intialize Something
//initialize tf
tf.addEventListener(MouseEvent.CLICK, onClick);
...
}
...
private function onClick(e:MouseEvent):void {
this.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
OK, I tried this in the constructor:
var mEvent:MouseEvent = new MouseEvent(MouseEvent.CLICK, true, false);
this.dispatchEvent(mEvent);
Then, in the containing textfield, while iterating through these objects (each of which is called cp), I did this:
cp.addEventListener(MouseEvent.CLICK, mouseClickHandler);
Finally the mouseClickHandler:
private function mouseClickHandler(event:MouseEvent):void
{
trace("Clicked!!!!!!!!!!!");
}
Running in debug mode I get nada. Nunca. Niente. Nuttin'. Which is to say: no trace of being clicked. Did I do something wrong?
I have a grid, when i click on the edit button it goes to edit page... but i need the value in the grid also to be passed to the page.
this.dispatchEvent(new DepManagementEvent(DepManagementEvent.EDIT_NAVI));
The above code lands in EDIT page... how can i move the values too.
My Parent Page code.
private function editForm():void {
var event:DepManagementEvent = new DepManagementEvent("Edit Page",true);
dispatchEvent(event);
}
The Edit Page below....
public function init(event:DepManagementEvent):void {
this.addEventListener(DepManagementEvent.EDIT_NAVI, onEditNavi);
}
public function onEditNavi(event:DepManagementEvent):void {
Alert.show("as");
}
I am not getting the alert, when the page is navigated from the parent one.... on click. Also edit this code on how i can pass the variables too.
Add a public var (called "navi" in the code below) to the DepManagementEvent that's of the same type as the item in the grid, then dispatch the event like this instead:
var event:DepManagementEvent = new DepManagementEvent( DepManagementEvent.EDIT_NAVI );
event.navi = grid.selectedItem;
dispatchEvent( event );
To listen to the event on the other side, you add an event listener for a function...
addEventListener( DepManagementEvent.EDIT_NAVI, onEditNavi);
private function onEditNavi( event:DepManagementEvent ):void
{
// add logic here
}
Since you're in an itemRenderer, you can dispatch a bubbling event that will move up to the parent List/DataGrid and continue to bubble up to other parent views in the display hierarchy. When you create the event, pass the second argument ("bubbles") as true:
new DepManagementEvent( DepManagementEvent.EDIT_NAVI, true );