View Full Version : Pushing Buttons From Code
I want to be able to have my code push a button.
I would like to visually see the button push, and to have all the listeners get called.
Is that possible?
Thanks
Al
CDHBookingEdge
12-20-2006, 09:15 PM
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function onButton1Pushed(): void
{
Alert.show("Hey I'm button 1 and someone told me to be pushed");
}
private function onButton2Pushed(): void
{
Alert.show("Hey I'm button 2 and I've been pushed");
pushedButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
]]>
</mx:Script>
<mx:VBox>
<mx:Button id="pushedButton" label="This button will be pushed when you click
the other button" click="onButton1Pushed();" />
<mx:Button id="buttonToPush" label="Push me!" click="onButton2Pushed();" />
</mx:VBox>
</mx:Application>
That should get you to the point of one event triggering another event. I triggered the action by click of another button. Now as far as seeing the button clicked..maybe you mean that it stay depressed, and that's for another subject, but we can see that the interactions of the two buttons are based on one another. As far as it's "depressed" state you would need to, I think, set it's toggle state/property to true, then it should remain "sticky" if it's not then we can delve into that further. And you can add the listeners in your initialization code and they will be called as normally. Again if you find that otherwise let me know.
Christopher
Assertnfailure
12-20-2006, 09:36 PM
At first I thought the title of this thread was "Pushing Cota's Buttons" xd
CDHBookingEdge
12-20-2006, 09:41 PM
LOL Haven't we all pushed Cota's buttons to the max? And all of ours? But then again, I could be wrong. By the way did you get the client you were dealing with that I naively tried to help on? LOL
Hope things are going ok with you,
Christopher
madgett
12-22-2006, 04:34 PM
I want to be able to have my code push a button.
I would like to visually see the button push, and to have all the listeners get called.
Is that possible?
Thanks
Al
What I would do is create a custom button that extends the Flex Button. This is actually very easy to do.
For example:
content/CustomButton.aspackage content
{
import mx.controls.Button;
import flash.events.MouseEvent;
import mx.events.FlexEvent;
import flash.utils.*;
public class CustomButton extends Button
{
private var Press:Boolean = true;
public function CustomButton():void
{
}
public function clickMe():void
{
if (Press)
{
dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, true));
}
else
{
dispatchEvent(new MouseEvent(MouseEvent.ROLL_OUT, true));
}
Press = !Press;
}
}
}
test.mxml<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:content="content.*">
<content:Test />
</mx:Application>
content/Test.aspackage content
{
import mx.core.Application;
import flash.utils.setInterval;
import content.CustomButton;
public class Test
{
private var interval:uint;
private var btn:CustomButton;
public function Test():void
{
btn = new CustomButton();
btn.label = "Click";
interval = setInterval(click, 1000);
Application.application.addChild(btn);
}
public function click():void
{
btn.clickMe();
}
}
}
I'm using a setInterval to do the clicking, but extending the button component will allow you to add your own customizations rather effectively.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.