header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Ramakrishna
Points:0
Posts:0

8/11/2010 12:31:39 AM

Title: Custom Events


Hi All,

My Question is:

I have 4 modules 1)payments
2) receipts
3) journals
4) purchases
and one components 1) buttons component

I have 4 components like payments, receipts, journals, purchases. In every component have 4 buttons like new, save, delete, cancel, but these buttons are placed in one components.

In Every component I am calling buttons component commonly, but my question is

i am writing functionality in every button in different component like inserting, deleting, editing. how to do it? please help me

How to write the functionality same buttons with different modules?

and how to get the button click handler in every module?
please help me?



1
Prestine
Points: 190
Posts:0
8/11/2010 2:54:49 AM



Hello,

Please use setter functions. This will help you identify, where buttons component is used.
Then you can dispatch custom events accordingly.


Hope this will show some light to you.

Regards,


2
Troy
Points: 820
Posts:0
8/11/2010 10:16:31 AM



you have to write button listeners for each module separately and you can attach the listeners to buttons

if buttons are in myButtons component and myButtons component is loaded inside module you can write myButtons.deleteBtn.addlistener(.. inside the module and similarly in other modules

3
Ramakrishna
Points: 0
Posts:0
8/11/2010 6:49:23 PM



Hi Troy,

Please provide any examples for this. Please help me


4
meoden8x
Points: 110
Posts:0
8/15/2010 2:20:53 AM



You need a global variables to keep track of current active module. Assume that the current active module is "receipts" and "new" button is clicked, you dispatch an event: "receipts_new_clicked". In main stage, you add an event listener to listen those events.

5
Prestine
Points: 190
Posts:0
8/15/2010 11:31:25 PM



Hello Ramakrishna,

Please run the following codes. Hope this is what you are looking for.
there are total 6 files :
main.mxml , Comp1.mxml , Comp2.mxml , Comp3.mxml , Comp4.mxml, CommonButton.mxml


1] main/mxml:


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
				layout="vertical" xmlns:local="*">
	
	<mx:Script>
		<![CDATA[
			
		]]>
	</mx:Script>
	
	<mx:Label text="Compenent 1" />
	<local:Comp1 />
	<mx:Spacer height=" 20" />
	<mx:Label text="Compenent 2" />
	<local:Comp2 />
	<mx:Spacer height=" 20" />
	<mx:Label text="Compenent 3" />
	<local:Comp3 />
	<mx:Spacer height=" 20" />
	<mx:Label text="Compenent 4" />
	<local:Comp4 />
	
	
</mx:Application>



2] Comp1.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
	
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			
				private function handleNewClick():void{
					Alert.show(" New Button Clicked from Comp1");
				}
				private function handleSaveClick():void{
					Alert.show(" Save Button Clicked from Comp1");
				}
				private function handleDeleteClick():void{
					Alert.show(" De;ete Button Clicked from Comp1");
				}
				private function handleCancelClicl():void{
					Alert.show(" Cancel Button Clicked from Comp1");
				}
				
			
		]]>
	</mx:Script>
	
	<local:CommonButton  newClick="handleNewClick()"
						 saveClick="handleSaveClick()"
						 deleteClick="handleDeleteClick()"
						 cancelClick="handleCancelClicl()"/>
</mx:VBox>



3] Comp2.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
	
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			
				private function handleNewClick():void{
					Alert.show(" New Button Clicked from Comp2");
				}
				private function handleSaveClick():void{
					Alert.show(" Save Button Clicked from Comp2");
				}
				private function handleDeleteClick():void{
					Alert.show(" De;ete Button Clicked from Comp2");
				}
				private function handleCancelClicl():void{
					Alert.show(" Cancel Button Clicked from Comp2");
				}
				
			
		]]>
	</mx:Script>
	
	<local:CommonButton  newClick="handleNewClick()"
						 saveClick="handleSaveClick()"
						 deleteClick="handleDeleteClick()"
						 cancelClick="handleCancelClicl()"/>
</mx:VBox>


4] Comp3.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
	
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			
				private function handleNewClick():void{
					Alert.show(" New Button Clicked from Comp3");
				}
				private function handleSaveClick():void{
					Alert.show(" Save Button Clicked from Comp3");
				}
				private function handleDeleteClick():void{
					Alert.show(" De;ete Button Clicked from Comp3");
				}
				private function handleCancelClicl():void{
					Alert.show(" Cancel Button Clicked from Comp3");
				}
				
			
		]]>
	</mx:Script>
	
	<local:CommonButton  newClick="handleNewClick()"
						 saveClick="handleSaveClick()"
						 deleteClick="handleDeleteClick()"
						 cancelClick="handleCancelClicl()"/>
</mx:VBox>



5] Comp4.mxml


<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
	
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			
				private function handleNewClick():void{
					Alert.show(" New Button Clicked from Comp4");
				}
				private function handleSaveClick():void{
					Alert.show(" Save Button Clicked from Comp4");
				}
				private function handleDeleteClick():void{
					Alert.show(" De;ete Button Clicked from Comp4");
				}
				private function handleCancelClicl():void{
					Alert.show(" Cancel Button Clicked from Comp4");
				}
				
			
		]]>
	</mx:Script>
	
	<local:CommonButton  newClick="handleNewClick()"
						 saveClick="handleSaveClick()"
						 deleteClick="handleDeleteClick()"
						 cancelClick="handleCancelClicl()"/>
</mx:VBox>


6] CommonButton.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Metadata>
	[Event(name="newClick")]
	[Event(name="saveClick")]
	[Event(name="deleteClick")]
	[Event(name="cancelClick")]
</mx:Metadata>

	<mx:Script>
		<![CDATA[
				
				private function handleNew():void{
					dispatchEvent(new Event("newClick"));
				}
				private function handleSave():void{
					dispatchEvent(new Event("saveClick"));
				}
				private function handleDelete():void{
					dispatchEvent(new Event("deleteClick"));
				}
				private function handleCancel():void{
					dispatchEvent(new Event("cancelClick"));
				}			
		]]>
	</mx:Script>
	
	<mx:Button label="New" click="handleNew()" />
	<mx:Button label="Save" click="handleSave()" />
	<mx:Button label="Delete" click="handleDelete()" />
	<mx:Button label="Cancel" click="handleCancel()" />	
	
</mx:HBox>
Hope this solves your problem. Regards,

6
Ramakrishna
Points: 0
Posts:0
8/19/2010 8:17:36 AM



Thank you very much modenBx.

Is there anyway to get the button ids in main application?


I want to get the button ids also...



Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 5+5 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions