Solved

call function in module

Posted on 2010-09-07
8
584 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Difference between FDS and LCDS 7 341
Converting PDF to SWF with video embedded 11 453
Video Playback in Flex Mobile App 4 1,475
Flex (as3) add parameters to addEventListener 2 749
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…
With the rapid rise in mobile usage, mobile devices are here to stay and have become an integral part of doing business. Here are 9 great apps for your BYOD environment.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

920 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