Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-20-2006, 06:35 PM   #1
AlG
Registered User
 
Join Date: Dec 2006
Posts: 10
Default 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
AlG is offline   Reply With Quote
Old 12-20-2006, 08:15 PM   #2
CDHBookingEdge
Registered User
 
Join Date: Oct 2006
Posts: 383
Send a message via MSN to CDHBookingEdge
Default

Code:
<?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
CDHBookingEdge is offline   Reply With Quote
Old 12-20-2006, 08:36 PM   #3
Assertnfailure
as[org].addListener(this)
 
Assertnfailure's Avatar
 
Join Date: Dec 2005
Location: LA, California
Posts: 837
Default

At first I thought the title of this thread was "Pushing Cota's Buttons" xd
Assertnfailure is offline   Reply With Quote
Old 12-20-2006, 08:41 PM   #4
CDHBookingEdge
Registered User
 
Join Date: Oct 2006
Posts: 383
Send a message via MSN to CDHBookingEdge
Default

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
CDHBookingEdge is offline   Reply With Quote
Old 12-22-2006, 03:34 PM   #5
madgett
is my last name...
 
Join Date: May 2004
Posts: 1,051
Default Extend mx.controls.Button

Quote:
Originally Posted by AlG View Post
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.as
Code:
package 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
Code:
<?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.as
Code:
package 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.
__________________
Anything is possible with Flash, it's just a matter of inventing the possibilities
Certified Swfwizard
madgett is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MC buttons - must wait SoundComplete b4 changin frames?? Seanx ActionScript 2.0 0 09-25-2006 04:34 PM
Please help with code (attachMovie,Array[index],linked buttons) studio08 ActionScript 2.0 1 12-19-2005 04:27 PM
Duplicating buttons with this code foot01 ActionScript 1.0 (and below) 1 03-05-2005 03:26 AM
Using Function Parameters to Code Multiple Buttons denniscruz ActionScript 2.0 2 02-22-2005 03:17 AM
why does this code disable my buttons? SeanPaul72 ActionScript 1.0 (and below) 6 03-19-2003 01:25 AM


All times are GMT. The time now is 11:58 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.