Avatar of kbnordvest
kbnordvest
 asked on

call function in module

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

Apache Flex

Avatar of undefined
Last Comment
kbnordvest

8/22/2022 - Mon
ChristoferDutz

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

ChristoferDutz

Argh ... dont' implement that in the main module, but in the module you want to call the function on ... sorry for that.
kbnordvest

ASKER
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()
Your help has saved me hundreds of hours of internet surfing.
fblack61
ChristoferDutz

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
kbnordvest

ASKER
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

ASKER CERTIFIED SOLUTION
ChristoferDutz

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
kbnordvest

ASKER
This has been a great learning experiance.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
kbnordvest

ASKER
Thanks. I doubled the points.