Solved

call function in module

Posted on 2010-09-07
8
588 Views
Last Modified: 2012-05-10
I am trying to call a function inside a module, from the application.

How is this done?

--- The function in the main application ---

public function cartUpdater():void {
	cartU();
}

--- The function in the module ---

public function cartU():void {
	serviceCartList.send();
}

Open in new window

0
Comment
Question by:kbnordvest
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 33617718
I would suggest you define an Interface (see attachment) and implement that in your main module file (simply add "implements" attribute). In your main application you can now call (assuming the instance of the module is called "modObj"):


public function cartUpdater():void {
      MyCoolInterface (modObj).cartU();
}

package {
public interface MyCoolInterface {
    function cartU():void;
}
}

Open in new window

0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 33617725
Argh ... dont' implement that in the main module, but in the module you want to call the function on ... sorry for that.
0
 

Author Comment

by:kbnordvest
ID: 33625717
I have made the interface and imported it into the main application and the module, where i want to call the function. However i get the following error, when i call the function. I also don't know how and where to incert the "implements" attribute.

TypeError: Error #1034: Type Coercion failed: cannot convert shop_cart_small$ to shop_cart_small_update_interface.
      at shop_item_view/cartUpdater()
      at mnvitmr::shop_item_tic/inCart_clickHandler()
      at mnvitmr::shop_item_tic/__inCart_click()
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 33626120
I created a small flex project demonstrating everything.

Unfortunately it took me twice as long to somehow provide the file as EpxertsExchange super intelligent file-scanner doesn't allow uploading fxp Files. It allways complains about content not being allowed. I therefore uploaded the File to my confluence and you can get it from there ... http://dev.c-ware.de/confluence/display/PUBLIC/Experts+Exchange+Files)

Hope it helps.

     Chris
0
 

Author Comment

by:kbnordvest
ID: 33634519
Great example, and easy to follow.
I can se you use the mx:ModuleLoader. I have been inserting my modules, as you can se in the attached code. Is it possible to get the interface to work with this?

<ns1:shop_cart_small x="800" y="32">
</ns1:shop_cart_small>

Open in new window

0
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 33634737
Oh! ... you aren't using modules, you simply created a custom component ... well that's a lot easier ;-)

Just as an info: When talking about "Modules", it ususally means that you have a flex application that dynamically loads another swf and uses that inside itself.

The difference is relatively small. if your compoenent is a mxml file, then you have to add the "implements" attribute to the root tag of your component and implement the function. Now if you have an explicit instance of your component:




then you can use this to call the function:

myCart.cartU()

If you want to iterate over a list of carts, you will have to use the Cast as I used it in my code.
0
 

Author Comment

by:kbnordvest
ID: 33634968
This has been a great learning experiance.
0
 

Author Closing Comment

by:kbnordvest
ID: 33634978
Thanks. I doubled the points.
0

Featured Post

Webinar: Security & Encryption in the MySQL world

Join Percona’s Solutions Engineer, Dimitri Vanoverbeke as he presents “Security and Encryption in the MySQL world” on Thursday, July 6, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
We take a look at some of the most common obstacles that IT teams run into as they work relentlessly to keep all the alarms and sirens from going off at once.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question