[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

call function in module

Posted on 2010-09-07
8
Medium Priority
?
591 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
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 2000 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

Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as the high-speed power of the cloud.

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…
Applications for our next round of the Experts Exchange Scholarship Contest are starting to roll in. It made us wonder what our past winners are up to these days. Here's a look at what four winners experienced with the contest and what they're doing…
Loops Section Overview
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 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