Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-27-2009, 06:27 PM   #1
aktell
FLEX Jokey
 
aktell's Avatar
 
Join Date: Jun 2007
Location: New Zealand
Posts: 154
Default Module communication ….

I’m working on a single modular application which has several levels and on these levels I do have a module which I use as a ‘Main Carrier module ***’ for other sub modules.
Now one of these Sub modules has a component attached, and I do need to ‘CLICK’ a button in that component which in return activates a certain ‘Click of a Button’ in the ‘Main Carrier module ***’ through a Button Click Handler or else?
I’m mostly interested in the idea and how to write and use the ‘Button Click handler’ etc.

*** Is NOT the Application module!!!

Any help would be appreciated very much since I have been looking for a couple of days and could not find anything.

Thanks in advance aktell

Last edited by aktell; 12-27-2009 at 06:30 PM.
aktell is offline   Reply With Quote
Old 12-28-2009, 06:02 AM   #2
Barna Biro
Senior Member
 
Barna Biro's Avatar
 
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,406
Default

There are a few ways to go when working with modules but the most straight forward would be to dispatch that CLICK event and subscribe to it in the main. Once the event is caught by the parent, you can react to it however you wish.
__________________
Titus M. Plautus - Not by age but by capacity is wisdom acquired.
Barna Biro is offline   Reply With Quote
Old 12-28-2009, 06:25 AM   #3
aktell
FLEX Jokey
 
aktell's Avatar
 
Join Date: Jun 2007
Location: New Zealand
Posts: 154
Default

Quote:
Originally Posted by Barna Biro View Post
There are a few ways to go when working with modules but the most straight forward would be to dispatch that CLICK event and subscribe to it in the main. Once the event is caught by the parent, you can react to it however you wish.
Thanks a lot Barna for your reply, but it is unfortunately not what I was looking for as there is no need to address the parent.Application 14 Levels down the track to only get up again doing what.
But it would be very helpful if you could answer one question 'If there is actually anything to addresses programmatic a Button click' because I have been spending quiet a few hours not finding a thing about it as everything is doing everything else but not the action programmatic 'Click'. ???

Thanks in advance aktell
aktell is offline   Reply With Quote
Old 12-28-2009, 06:39 AM   #4
Barna Biro
Senior Member
 
Barna Biro's Avatar
 
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,406
Default

Ok, just a sec there I have just woke up and didn't read the problem correctly. So you are in fact trying to simulate a CLICK within a module? If that's the case then why don't you simply call the method associated with that button's CLICK handler? I mean:

- let's say you have a button and it has a click handler that points to a method called "handleButtonClick"
- You would make "handleButtonClick" public and you'd simply call it from the outside whenever you want to "simulate a click" ( like: yourModule231.handleButtonClick(); ).

I hope I understood the problem right this time. In case I didn't, then please try to explain again ( some actual code wouldn't hurt either ).

EDIT: the name "handleButtonClick" is not the coolest on the block when doing stuff like this, instead it should have a more meaningful name... for example: if the click would trigger a script that would send an e-mail, then the method could be called "sendEmail"... also, you can always keep the handler "handleButtonClick" and leave it private/protected/internal and have a second method called "sendEmail" which is public, and simply call it from within the "handleButtonClick"... from outside the module, obviously, you wouldn't have to waste time calling a handler ( and I think it's a bit better this way too ), but you could/should call the "sendEmail" method directly ( since in essence, that's what you want to trigger ).
__________________
Titus M. Plautus - Not by age but by capacity is wisdom acquired.

Last edited by Barna Biro; 12-28-2009 at 06:49 AM.
Barna Biro is offline   Reply With Quote
Old 12-28-2009, 08:49 AM   #5
aktell
FLEX Jokey
 
aktell's Avatar
 
Join Date: Jun 2007
Location: New Zealand
Posts: 154
Default

While you just woke up I have to go to bed here in NZ it’s nearly midnight!
Anyway, I try to explain quickly:
I have a main module which is the carrier of some sub-modules, and now I want to click a btn. in one of the sub-module to programmatically click a btn. in the main module to select a module different from the one which is visible at the moment (Swap). I do not have any code as I try to work this out but have not been able to crack it.

There is a small item to it that also sometimes a sub-module has a component attached and the btn. to click would be in there.

I hope that is understandable English as this is not my first language either.

Thanks aktell
aktell is offline   Reply With Quote
Old 12-28-2009, 12:14 PM   #6
Barna Biro
Senior Member
 
Barna Biro's Avatar
 
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,406
Default

Ok, the description is still a bit confusing to me, but here's what I understood until now:

1) You have the main application that loads in / holds multiple modules.
2) Not all the modules are visible at once ( maybe they are in a view stack or something ).
3) Modules have buttons inside of them that once clicked, should communicate with the main application ( or the container holding the currently clicked module ) and depending on the event, the container/application should hide/show a new module.

I have no idea what you understand by "to programmatically click a btn" Do you want to simulate the click event without the user actually clicking a button? ( I already described how this should be handled in my previous reply ).

To sum things up: ideally, you should dispatch custom events from your modules and the container holding those modules should subscribe to those events. Once you click a button in a module, you dispatch the event that is then caught by the container holding the module. From that point on, you can react to the event as you wish ( you can remove the current module and display a new one... swap modules, or do something else... it's up to you ).

In case I still didn't understand what you want ( I'm not sleepy now so I hope I did ) then either try to explain it again ( but try to be as clear as possible this time... the above reply is a bit more confusing than the first one to be honest... ) or wait for someone else to drop by who'll hopefully understand what you want to do

English ain't my native language either...
__________________
Titus M. Plautus - Not by age but by capacity is wisdom acquired.
Barna Biro is offline   Reply With Quote
Old 12-30-2009, 04:54 AM   #7
aktell
FLEX Jokey
 
aktell's Avatar
 
Join Date: Jun 2007
Location: New Zealand
Posts: 154
Default

Thanks for your reply, sorry for not replying sooner, but I had to return to work unexpected.
Quote:
1) You have the main application that loads in / holds multiple modules.
Yes, an application which works on around 14 levels and has between 70 to 80 modules.

Quote:
2) Not all the modules are visible at once ( maybe they are in a view stack or something ).
Yes, all levels are operating within ViewStacks, but they are several levels active at one time layered and actively working.

Quote:
3) Modules have buttons inside of them that once clicked, should communicate with the main application (or the container holding the currently clicked module ) and depending on the event, the container/application should hide/show a new module.
No not quiet! there is only one button available and that is the one I like to work with and have not been able as yet. There are more buttons are available but they work on some of the levels and do not address or inter-communicate with the ‘parentApplication’ only on there own levels! Not even to or in between the modules.
There are only two of the modules in total which are used by the ‘parentApplication’ to get to the rest.

Quote:
I have no idea what you understand by "to programmatically click a btn" Do you want to simulate the click event without the user actually clicking a button? ( I already described how this should be handled in my previous reply ).
I just mean by programmatically: ‘Code’ not by clicking the button. And yes that is what I would like to do ‘Simulate the Click of a button’ or exchange text strings between modules or child module to the level carrier-module (parent).

Here is some code which I used reasoned, and which I got working between sub-module (child) and level carrier-module (it’s parent).
Nothing else seems to work what I have tried over time. No other code between modules or sub-module (child) and level carrier-module (parent).

Thanks in advance aktell

Code:
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    
    layout="vertical">

    <mx:Script>
        <![CDATA[
            private var myModCom:Object;

            private function moduleComHandler():void {

                myModCom = moduleLoader.child as Object;
                myModCom.addEventListener( "submit", submitHandler );
            }

            private function submitHandler( evt:Event ):void {

				textI1.visible = false;
            }
        ]]>
    </mx:Script>

    <mx:ModuleLoader 
    	id="moduleLoader"
        url="ContactEntry.swf"
        ready="moduleComHandler();"/>

    <mx:TextInput id="textI1"/>

</mx:Application>
Code:
<mx:Module
    xmlns:mx="http://www.adobe.com/2006/mxml"

    layout="vertical"
    width="100%" height="100%">

	    <mx:Metadata>
	        [Event(name="submit", type="flash.events.Event")]
	    </mx:Metadata>
	
	    <mx:Script>
	        <![CDATA[

	            public static const SUBMIT:String = "submit";
	
	            private function submitHandler():void {

	                dispatchEvent( new Event(SUBMIT));
	            }
	        ]]>
	    </mx:Script>

	        <mx:Button label="submit" click="submitHandler();"/>

</mx:Module>

Last edited by aktell; 12-30-2009 at 05:56 AM.
aktell is offline   Reply With Quote
Old 12-30-2009, 09:01 PM   #8
Barna Biro
Senior Member
 
Barna Biro's Avatar
 
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,406
Default

Well, yeah... In essence, what you did is ok. You have subscribed to an event that is dispatched from within the module and reacted to it in the parent. Seems all ok to me. I personally don't like modules ( I feel they more often lead to messy things than actually help ). You could maybe try playing around with the Observer Pattern as well ( it may not suit your current needs but it's good to know that it's there ). So, listening to events and dispatching events when change happens is all ok.
__________________
Titus M. Plautus - Not by age but by capacity is wisdom acquired.
Barna Biro is offline   Reply With Quote
Old 12-30-2009, 09:36 PM   #9
aktell
FLEX Jokey
 
aktell's Avatar
 
Join Date: Jun 2007
Location: New Zealand
Posts: 154
Default

Hi again Barna,

Appreciate your reply even so it made me smile a little as it is for me back to the grind stone.
I started working with module two years ago and for myself I never ever would go or look back imagining working without them!
While starting and laying out this app. in question in June. 2008 I had the problem we have discussed here coming up immediately but was able until now to avoid the use of any of it, and which got me to work out many interesting ideas! I have tried a few times to get behind this problem, but never as yet had any luck with that.
Never the less I have been able to sort the problem at hand for the moment with only one line of Php code! Still are not able to simulate the ‘Click the btn’ but maybe in time there will be a cure.
Thanks again for your effort aktell
aktell is offline   Reply With Quote
Old 12-30-2009, 09:45 PM   #10
Barna Biro
Senior Member
 
Barna Biro's Avatar
 
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,406
Default

Simulating it is possible. All that you need to do ( as I have already mendioned ) is to make submitHandler() public and simply call it... calling it will execute the chain of actions that would have been executed if the user would have pressed the button and there you are! There's only one problem from my side... I seriously have no idea why you'd want to do something like this. I'd personally think that it's a design flaw ( something was wrongly planned ), because I can't see any situation where one should "simulate a button click"... it's totally "ok" to execute a certain script/part when needed ( that's why certain methods are public ) but why simulate a click? no idea... Or maybe I've just "got stuck" at this whole simulation thingie and I'm missing out on the bigger picture...

Anyway, if you want to "simulate the click" then simply do it by putting the logic that is inside the click handler into a public method and call that method whenever you want to "simulate the click".
__________________
Titus M. Plautus - Not by age but by capacity is wisdom acquired.

Last edited by Barna Biro; 12-30-2009 at 10:02 PM.
Barna Biro 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


All times are GMT. The time now is 10:43 AM.

///
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.