Skip to main content
Known Participant
May 7, 2009
Question

Calling a function in an external actionscript

  • May 7, 2009
  • 1 reply
  • 977 views

Hi. First of all I'd like to put my hands up and say that what I know about Flash is antiquated (I used to work with Flash 4 / 5), and have now been thrown into the deep end, as it were.

I have an application that has a button component. In an external actionscript file there's an event listener that calls a function when this button is pressed. I want to replace the button with a graphic that switches according to whether the button is 'on' or 'off'. I've created a movie clip that cycles back and forth between the on and off states when clicked, but the trouble I'm having is getting it to call the function. I have no idea how to do it, other than to just include function_name(); (or call.function_name();) in the onRelease handler (which doesn't work). Is it possible to use event listners for movie clips (rather than components?) Or else how can I call this function? It should be really simple and I'm tearing my hair out trying to get it to work! The function is declared 'public', by the way...

Oh yes, this is ActionScript 1 (I think...)

Eternal thanks and gratitude to anyone who can help me...

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
May 7, 2009

copy and paste the code in that external .as file.

Known Participant
May 8, 2009

Do you mean to copy it here, or copy it into the fla? I've already tried doing the latter, which doesn't work - the script imports other external as files and I think that that's messing things up. The function only seems to work when it's located in this external file. The function I'm trying to call is

public function toggleAudio() {
       //if (btnAudio.label == "Sound Off") {
       if (_root.audio == "mute" or btnAudio2.label == "Sound Off") {
           trace("toggleAudio AUDIO: Off");
           //btnAudio.label = "Sound On";
           _root.audio = "unmute";
                     // stop recieving audio from in stream
           ServiceLocator.getInstance().getService("nsService").returnInStream().receiveAudio(false);
           // stop sending audio on out stream
           ServiceLocator.getInstance().getService("nsService").returnOutStream().attachAudio(null);
                 } else {
           trace("toggleAudio AUDIO: On");
           btnAudio2.label = "Sound Off";
           _root.audio = "mute";
                     // start recieving audio from in stream
           ServiceLocator.getInstance().getService("nsService").returnInStream().receiveAudio(true);
           // start sending audio on out stream
           ServiceLocator.getInstance().getService("nsService").returnOutStream().attachAudio(ServiceLocator.getInstance().getService("camService").returnMic());
       }
   }

The bit at the beginning where I've commented some stuff out is where I've been trying out different things to get it to work.
For all intents and purposes though the function could be

public function please_work() {
trace("I work!");
}

All I need is for a way to call this from the main flash movie

kglad
Community Expert
Community Expert
May 8, 2009

i meant to paste the code here so we could see the code.

if toggleAudio() is the function called when your button is pressed, what  code calls that function?