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

How can i apply a function multiple times in action script?

New Here ,
Apr 18, 2017 Apr 18, 2017

I have a menu bar which need to use the function multiple times, how can i make the function reusable in every scene/frame?

281
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
LEGEND ,
Apr 18, 2017 Apr 18, 2017

Scripts that are in frame 1 should be usable in any other frame. Do you have an example FLA that you can put online somewhere, that shows the problem you're having?

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
New Here ,
Apr 18, 2017 Apr 18, 2017

But I have different scene which need to use the same function as well.

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
LEGEND ,
Apr 18, 2017 Apr 18, 2017

The script in frame 1 of scene 1 should still work in scene 2. I tried this script in scene 1:

test();

function test(){

  trace("test1");

}

and this in scene 2:

test();

stop();

It traced "test1" twice. So, scene 2 was able to use scene 1's function.

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
New Here ,
Apr 18, 2017 Apr 18, 2017

Okay, thanks. Can i know how to pause audio and play back from last position without declare

var mySound:Sound = new Sound();

I want to stop the frame and play it when click on "play" button.

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
LEGEND ,
Apr 18, 2017 Apr 18, 2017

Any sounds that you cut off with a blank keyframe in scene 1 will not be heard in scene 2.

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
LEGEND ,
Apr 18, 2017 Apr 18, 2017

Also, these lines of script will stop everything:

import flash.media.SoundMixer;

SoundMixer.stopAll();

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
New Here ,
Apr 18, 2017 Apr 18, 2017
LATEST

SoundMixer.stopAll(); will stop all the sound but how can i pause it and play it from the last position? i tried as below

var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var myTransform = new SoundTransform();
var lastPosition:Number = 0;

myChannel = mySound.play();
myTransform.volume = 0.5;
myChannel.soundTransform = myTransform;

pause_btn.addEventListener(MouseEvent.CLICK, onClickPause);

function onClickPause(e:MouseEvent):void{
lastPosition = myChannel.position;
myChannel.stop();
}

play_btn.addEventListener(MouseEvent.CLICK, onClickPlay);

function onClickPlay(e:MouseEvent):void{
myChannel = mySound.play(lastPosition);
myChannel.soundTransform = myTransform;
}

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