Link to home
Start Free TrialLog in
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

Avatar of ChristoferDutz
ChristoferDutz
Flag of Germany image

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

Argh ... dont' implement that in the main module, but in the module you want to call the function on ... sorry for that.
Avatar of kbnordvest
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()
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
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
Avatar of ChristoferDutz
ChristoferDutz
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This has been a great learning experiance.
Thanks. I doubled the points.