Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

call a function out of loaded swf

Guest
Aug 12, 2008 Aug 12, 2008
Hello,

I try to build a reader app with Flex.
The app should display external SWFs.

Example:
I load a swf ("page.swf") into a loader in "reader.swf".

In page.swf are some buttons.
Each button has its eventListener:
buttonxyz.addEventListener(MouseEvent.CLICK, show_info);

The function "show_info" reads the eventTarget and makes some action depending on the target.

Here ist the problem:
The function "show_info" is not part of page.swf. It is part of reader.swf.
I tried different ways to call the function, but it did not work.

When compiling page.swf I get the error that the function "show_info" is not part of page.swf.

Can anyone explain how I get this to work?

Thanks
Beneq
TOPICS
ActionScript
372
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 12, 2008 Aug 12, 2008
I would advise catching the MouseEvent buttons, then dispatching events to a global location (See Cairngorm Event). This is a global app event dispatcher where every object can dispatch custom events from and hear events... Or have all your elements dispatch to the stage... and have a stage-based listener that handles all events.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 12, 2008 Aug 12, 2008
Thank you, ccoonen.

Could you please send a short example how to dospach and read an event to / from the stage?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 13, 2008 Aug 13, 2008
LATEST
OK, ccoonen, I got it to work like this:

In page.swf are only the buttons, no ActionScript.

In reader.swf I have an EventListener that listens to the stage:
---> stage.addEventListener(MouseEvent.CLICK, show_info);

By event bubbling the CLICK will reach the stage.

The function show_info reads the name of the eventTarget and does its action.

This works, but there are some quirks:
1. This woks only with MouseEvent.CLICK, no ROLL_OVER, ROLL_OUT or DOUBLE_CLICK...
2. This listens to all the clicks the user does. And the function has to filter out all objects that do not interest for the action...
3. If it would work with ROLL_OVER and ROLL_OUT, too, this would listen to nearly all mouse action... I think this would not be very efficient...

Am i doing something wrong?
Are there better solutions?

Benedikt
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines