actionscript 3 - How call the function that is in my main.mxml app from a as3 class in Flex -


i write sound playback class stop older sound , play new sound.after need method in class trigger when sound play complete.i achieve this, need inform main app (main.mxml) completion of sound playing. how ? in advance.

here sound playback class.

package com.m2b.data {     import flash.events.event;     import flash.media.sound;     import flash.media.soundchannel;     import flash.media.soundmixer;     import flash.net.urlrequest;      import mx.controls.alert; public class soundplayback {     private var channel:soundchannel = new soundchannel();     private var sm:soundmixer = new soundmixer();     public  var snds:sound;       public function soundplayback()     {         // constructor function     }     /** call if need close previous sound , play new 1 **/     public function playsound():void{         // stopall method used close/shutdown sound          // in domin describe in cross doamin         soundmixer.stopall();         // play new sound.         channel = snds.play();         channel.addeventlistener(event.sound_complete, soundcomplete);     }     /** call when new sound play without stop old sounds**/     public function playallsound():void{         // play new sound.         channel = snds.play();         }         private function soundcomplete(e:event):void{             alert.show('<<<< complete >>>>>>');         }     } } 

and here function pass sound obj param class , call play sound method playing sound.

//tahir - play sound (close previous sound , play new one) private var soundplayer:soundplayback = new soundplayback(); private function welcomepackage():void{   soundplayer.snds = loaderqueue.getsound('cv-welcome'+randomnumber(1,3));  soundplayer.playsound();  } 

thanks.

the easiest way this, dispatching , listening custom-events. can read more here. essentially, you're creating event listener on main class, , dispatching custom event sound player.

hope helps.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -