Flash/Actionscript 3 - embedded sound play/stop? -
how play/stop embedded music file in flash/as3 via button?
this have:
import flash.events.event; import flash.events.mouseevent; import flash.display.movieclip; import flash.media.sound; import flash.media.soundchannel; var mymusic:sound = new themesong(); var channel:soundchannel = mymusic.play(); startbutton.addeventlistener(mouseevent.click, onstartclick); stopbutton.addeventlistener(mouseevent.click, onstopclick); function onstartclick(event:mouseevent):void{ mymusic.play(); } function onstopclick(event:mouseevent):void{ mymusic.stop(); }
themesong name of class assigned music file (import -> libraries -> properties -> export -> class name). startbutton , stopbutton identifiers buttons.
if run i'll error saying:
"scene 1, layer 'actions', frame 1, line 69 1061: call possibly undefined method stop through reference static type flash.media:sound."
thanks.
you're close flash wonky sometimes:
import flash.events.event; import flash.events.mouseevent; import flash.display.movieclip; import flash.media.sound; import flash.media.soundchannel; var mymusic:sound = new themesong(); var channel:soundchannel = mymusic.play(); startbutton.addeventlistener(mouseevent.click, onstartclick); stopbutton.addeventlistener(mouseevent.click, onstopclick); function onstartclick(event:mouseevent):void{ channel = mymusic.play(); } function onstopclick(event:mouseevent):void{ channel.stop(); }
Comments
Post a Comment