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

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

New Here ,
Apr 18, 2017 Apr 18, 2017

Copy link to clipboard

Copied

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

Views

143

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Also, these lines of script will stop everything:

import flash.media.SoundMixer;

SoundMixer.stopAll();

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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;
}

Votes

Translate

Translate

Report

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