Solved

call function in module

Posted on 2010-09-07
8
587 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

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…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

697 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