Solved

call function in module

Posted on 2010-09-07
8
582 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
  • 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now