-
Stop Function to a Gallery
Im using AS3
I have 3 scenes ...
One is a 'links' page that I use to navigate to websites, a video and a gallery.
The gallery is on a scene of its on, on the links page I have a button that takes you to it, and starts it.
The gallery Im using isnt one I made myself ...
I need to stop it - but cant figure how.
When I am done with watching the gallery I want to navigate back to the links page, I can get that to happen - but the gallery - with music is still going in the background.
This is all the gallery code:
Code:
stop();
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.filters.GlowFilter;
import flash.filters.DropShadowFilter;
import flash.utils.Timer;
import flash.events.TimerEvent;
////
var myArray:Array = ["Fun at Cullburra Beach", "Safe & Protected at Tilbury Cove", "Holiday Time in the Shoalhaven", "Running Along Seven Mile Beach", "Beautiful Abraham's Bosom, Currarong" , "Family Time at Plantation Beach, Vincentia " , "Off Leash Fun at Moona Moona, Husskinson"];
var myGlow:GlowFilter = new GlowFilter(0xffffff,1,10,10,255);
var myShadow:DropShadowFilter = new DropShadowFilter(6);
var totalImages=7;
var imageNumber=1;
var myTimer:Timer = new Timer(4000);// 4 sec
var myLoader:Loader = new Loader();
////
var myRequest:URLRequest = new URLRequest("Images/"+imageNumber+".png");
myLoader.load(myRequest);
addChildAt(myLoader,1);
////
myLoader.contentLoaderInfo.addEventListener(Event.INIT, getImageInfo);
function getImageInfo(event:Event){
var imgX=(stage.stageWidth- myLoader.width)/2;
var imgY=(stage.stageHeight- myLoader.height)/2;
myLoader.x=imgX;
myLoader.y = imgY;
myLoader.filters = [myGlow, myShadow];
var myTween:Tween = new Tween(myLoader, "alpha", None.easeNone, 0,1,2,true);
}
////
myTimer.addEventListener(TimerEvent.TIMER, autoadvance);
function autoadvance(event:TimerEvent){
if(imageNumber<totalImages){imageNumber++}
else (imageNumber=1);
reload();
}
myTimer.start();
////
rightButton.addEventListener(MouseEvent.CLICK, nextImage);
function nextImage(event:MouseEvent){
if(imageNumber<totalImages){imageNumber++}
else (imageNumber=1);
reload();
}
////
leftButton.addEventListener(MouseEvent.CLICK, previousImage);
function previousImage(event:MouseEvent){
if(imageNumber>1){imageNumber--}
else (imageNumber=totalImages);
reload();
}
////
function reload(){
removeChild(myLoader);
myRequest= new URLRequest("Images/"+imageNumber+".png");
myLoader.load(myRequest);
addChildAt(myLoader,1);
myLabel.pictureLabel.text = myArray[imageNumber-1];
var tweenLabel:Tween = new Tween(myLabel, "rotation", Bounce.easeOut, 360, 390,1,true)
}
////
var my_sound:Sound = new Sound();
my_sound.load(new URLRequest("honky_tonk.mp3"));
var my_channel:SoundChannel = new SoundChannel();
my_channel = my_sound.play(0,9999);
////
//stopping the timer.
stage.addEventListener(MouseEvent.MOUSE_MOVE, stop_the_Timer);
function stop_the_Timer(event:MouseEvent){
myTimer.stop();
}
////resume timer
stage.addEventListener(Event.MOUSE_LEAVE, resumeTimer);
function resumeTimer(event:Event){
myTimer.start();
}
////////////
-
How are you exiting out of the scene? Is it on a button press? I'm going to assume it is from a button called exit_btn. Here is the code that I think will work:
Code:
exit_btn.addEventListener(MouseEvent.CLICK, leaveGallery);
function leaveGallery(e:MouseEvent):void{
//stop timer and remove listener
myTimer.stop();
myTimer.removeEventListener(TimerEvent.TIMER, autoadvance);
//remove listeners on left right buttons
rightButton.removeEventListener(MouseEvent.CLICK, nextImage);
leftButton.removeEventListener(MouseEvent.CLICK, previousImage);
//stop the sound
my_sound.stop();
}
that should do it.
-
Thanks for the suggestion but it didnt work ....
I just want to stop/exit this gallery .... Ugh ! ! !
this is the error, i get when I try your code suggestion:
gallery, Layer 'action', Frame 511, Line 112 1061: Call to a possibly undefined method stop through a reference with static type flash.media:Sound.
-
Ok playing around with it more - I removed the gallery from a button activated start point/page and just put it on auto start in its own scene.
I have the music stopping - but when I progress to a new scene via a next scene button - the gallery is still running (no sound though).
I copied the error msgs I got as I let the gallery con't to run in the background of the next scene - which is a static 'links/navigation' page.
Error msgs:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at tj_final_withtoys_close_fla::MainTimeline/reload()
at tj_final_withtoys_close_fla::MainTimeline/autoadvance()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at tj_final_withtoys_close_fla::MainTimeline/reload()
at tj_final_withtoys_close_fla::MainTimeline/autoadvance()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at tj_final_withtoys_close_fla::MainTimeline/reload()
at tj_final_withtoys_close_fla::MainTimeline/autoadvance()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at tj_final_withtoys_close_fla::MainTimeline/reload()
at tj_final_withtoys_close_fla::MainTimeline/autoadvance()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at tj_final_withtoys_close_fla::MainTimeline/reload()
at tj_final_withtoys_close_fla::MainTimeline/autoadvance()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at tj_final_withtoys_close_fla::MainTimeline/reload()
at tj_final_withtoys_close_fla::MainTimeline/autoadvance()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
-
sorry I forgot to add in the code
removeChild(myLoader);
that will remove the image gallery. Let me know if you are still having issues with errors.
-
Thank You ....
Can't wait to try it - up to my eyeballs in an essay at the moment.
Flash is my reward/treat, my carrot to get me through stuff I don't want to do.
Really looking forward to trying this - many thanks for your time ....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|