Groups | Blog | Home
all groups > flash actionscript > april 2005 >

flash actionscript : Using a btn to jump to another scene


mmh166
4/19/2005 9:39:12 PM
OK, I am stumped. I have three scenes in my movie. Scene 1 is a simple intro
animation. Scenes 2 and 3 each contain mediadisplay components that play
external FLV files. I am able to get flash to jump from scene 1 to scene 2
without problem. I am also able to get scene 2 jump to scene 3 using the "
displayListener.complete" function. This works well... once the video in scene
2 is done, scene 3 loads and the video plays without problem. I would now like
to add a button that allows the user to skip from any point in scene 2 to scene
3, thus allowing the user to not have watch the entire video just to get to the
next scene. The way I have it now, once you click the button, it stops playing
scene two and takes you to a static shot of the media displayPlayback. Scene 3
doesn't play at all. I am really stumped. I attached my code for scene 2
below. Anyone know how I can code it so that the button can take the user from
scene 2 to scene 3 and also have scene 3 play???




stop();
display.autoPlay = true;
display.activePlayControl = true;
display.controllerPolicy = "on";
display.totalTime = 56;
var displayListener:Object = new Object();
displayListener.complete = function(){
gotoAndPlay("scene_3", 1);
}
displayListener.cuePoint = function(eventObj:Object){
var index = Number(eventObj.target.name);
cue_txt.text = cueTextArray[index];
}
display.addEventListener("cuePoint", displayListener);
display.addEventListener("complete", displayListener);
display.addCuePoint("0", 1)
display.addCuePoint("1", 8)
display.addCuePoint("2", 14)
display.addCuePoint("3", 31)
display.addCuePoint("4", 35)
display.addCuePoint("5", 53)
display.addCuePoint("6", 56)
var cueTextArray:Array = new Array();
cueTextArray[0] = "one";
cueTextArray[1] = "two";
cueTextArray[2] = "three";
cueTextArray[3] = "four";
cueTextArray[4] = "five";
cueTextArray[5] = "six";
cueTextArray[6] = "seven";
display.setMedia("scene2_clip.flv", "FLV");

btn_next_intro.onRelease = function(){
display.stop();
gotoAndPlay("scene_3", 1);
}
mmh166
4/19/2005 9:44:41 PM
mmh166
4/20/2005 12:00:00 AM
Jeckyl
4/20/2005 12:00:00 AM
Read one of the MANY MANY posts here that tell you DO NOT EVER EVER use
scene names for navigation. Ever.

Also NEVER EVER use gotoAndPlay or gotoAndStop without some sort of
dot-prefix (ie do not use gotoAndPlay .. instead use this.gotoAndPlay,
_root.gotoAndPlay, _parent.gotoAndPlay etc etc as appropriate) or you can be
bitten by Flash bugs.

Use frame labels and dot prefixes and all is fine
--
Jeckyl

kglad
4/20/2005 12:00:00 AM
in general, it's a bad idea to use scene information for navigation. give your
keyframes labels and use the labels for navigation:

_root.gotoAndPlay("scene3_frame1"); // where label frame1 of scene3
appropriately
mmh166
4/20/2005 10:56:38 AM
kglad
4/20/2005 2:54:58 PM
scenes are just a convenience during authoring. they help (some) people
organize their project. they serve no purpose during runtime.

i've never used scenes and can't envision a circumstance when i would use
scenes. i do like breaking projects into modules to facilitate organizing a
complex project, but i like to keep them completely separate and load the
modules as distinct swfs. using separate swfs also helps simplify complex
projects and has the added benefit of minimizing the user's wait time.
mmh166
4/20/2005 9:00:47 PM
OK, I followed your advice, ditched the scene navigation, and switched to frame
label navigation. BUT, I am still having the same problem. The complete
function works and the the second FLVs load nicely once the first FLV is done
playing. However, I am still unable to get the second FLV to play by clicking
on the button. Is there something wrong with the code specifically for the
button. The code is attached. Again, the button's instance name is
btn_next_intro

stop();

display.autoPlay = true;
display.activePlayControl = true;
display.controllerPolicy = "on";
display.totalTime = 56;
var displayListener:Object = new Object();
displayListener.complete = function(){
_root.gotoAndPlay("three");
}
displayListener.cuePoint = function(eventObj:Object){
var index = Number(eventObj.target.name);
cue_txt.text = cueTextArray[index];
}
display.addEventListener("cuePoint", displayListener);
display.addEventListener("complete", displayListener);
display.addCuePoint("0", 1)
display.addCuePoint("1", 8)
display.addCuePoint("2", 14)
display.addCuePoint("3", 31)
display.addCuePoint("4", 35)
display.addCuePoint("5", 53)
display.addCuePoint("6", 56)
var cueTextArray:Array = new Array();
cueTextArray[0] = "one";
cueTextArray[1] = "two";
cueTextArray[2] = "three";
cueTextArray[3] = "four";
cueTextArray[4] = "five";
cueTextArray[5] = "six";
cueTextArray[6] = "seven";
display.setMedia("two.flv", "FLV");

btn_next_intro.onRelease = function(){
display.stop();
_root.gotoAndPlay("three");
}
kglad
4/20/2005 9:04:47 PM
do you have a frame labelled "three" on your _root timeline? if so, what's the
problem?

if not and you really intend to play the 3rd frame of your _root timeline you
should use:

_root.gotoAndPlay(3);
mmh166
4/20/2005 9:07:10 PM
I went ahead and create a extra frame label to test the button and it works
fine. It just won't work when there is an FLV waiting for it. It's really got
me stumped as the FLV will work if the complete function is allowed to work and
the the button will work so long as there is no FLV. What's the deal?
mmh166
4/20/2005 9:07:26 PM
I went ahead and created an extra frame label to test the button and it works
fine. It just won't work when there is an FLV waiting for it. It's really got
me stumped as the FLV will work if the complete function is allowed to work and
the the button will work so long as there is no FLV. What's the deal?
kglad
4/20/2005 9:13:28 PM
mmh166
4/20/2005 9:19:03 PM
When I jump from the frame that contains the first FLV to the frame that
contains the second FLV via the button, the second FLV (the one that's waiting,
so to speak), will not play. I see the playback display, but it does not play.
The second FLV will play without a problem if I let the first one play through
to allow the complete function to execute.
kglad
4/20/2005 9:20:56 PM
mmh166
4/20/2005 9:23:34 PM
I think so.. I say this because it will play automatically if the complete
function is allowed to happen once the first FLV plays. The code for the
second FLV is attached

display.setMedia("three.flv", "FLV");
stop();

display.autoPlay = true;
display.activePlayControl = true;
display.controllerPolicy = "on";
display.totalTime = 39;
mmh166
4/20/2005 9:25:05 PM
mmh166
4/20/2005 9:26:37 PM
kglad
4/20/2005 9:33:00 PM
mmh166
4/20/2005 9:34:40 PM
mmh166
4/20/2005 9:37:09 PM
YOu got me thinking that maybe both instances of the playback display can't
share the instance name of display. I changed the second instance name of the
display and made the change in the code and it works!!!!
kglad
4/20/2005 9:38:51 PM
mmh166
4/20/2005 9:41:47 PM
I don't understand why having the same instance name would work with the
complete function but not with the button. Either way, as long as it works
both ways, I'm a happy camper. Thanks so much for taking the time to help me
working through this very mind-numbing problem. I appreciate it a lot.
kglad
4/20/2005 10:06:05 PM
you're welcome. components are, at best, a mixed blessing. their benefits are
obvious. their drawbacks include lack of flexibility and problems that may
arise from their use that can not be understood without understanding the
construction of the component.

that said, there are problems enough from using simple objects that have the
same name so it's no great surprise that using components with the same name
would cause a problem. even using a textfield that has the same instance name
as variable name can cause problems.

bottomline: always use distinct names for distinct objects.
AddThis Social Bookmark Button