• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1479
  • Last Modified:

How do I navigate between scenes with Actionscript 3.0 without getting Error #2108 Scene not found

This seems to be a common problem, but I can't find a solution that works for me. I have an fla file with 6 scenes. On the first scene, I have navigation buttons that I want to program to go to each scene.

I created a function for one button but I keep getting this output error:

ArgumentError: Error #2108: Scene SceneGP was not found.
      at flash.display::MovieClip/gotoAndStop()
      at OPID_lovejoy_working_SceneHM_fla::MainTimeline/switchScene()

The trace is working; switching scenes is not. Am I not navigating to it correctly?

//"overview" is the frame label and "SceneGP" is the scene name

	this.navDrop_mc.galleryHM_btn.addEventListener(MouseEvent.CLICK, switchScene);


//function to switch scenes based on which button was selected from dropdown menu
function switchScene (evtObj:MouseEvent):void {
//trace to test function
	trace ("Button was selected from drowpdown menu");
	gotoAndStop("overview","SceneGP");
}

Open in new window

0
beemerrider130hp
Asked:
beemerrider130hp
  • 8
  • 5
1 Solution
 
TanLiHaoCommented:
Try using

MovieClip(root).gotoAndStop("overview", "SceneGP");
0
 
blue-genieCommented:
i setup 2 scenes, pasted your code as is into the first scene.
create a movieclip called navDrop_mc and then another inside called galleryHM_btn and it works perfectly.

check your scene names.
0
 
beemerrider130hpAuthor Commented:
Still getting same error with
MovieClip(root).gotoAndStop("overview", "SceneGP");


My scene names are correct. In fact, I've tried the code with all my different scene names with same error. Can you send me your sample file so I can try to determine what is different about yours that is making it work? In my file, galleryHM_btn is an actual button symbol, not a movieclip button. Would that make a difference?

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
TanLiHaoCommented:
It doesn't matter whether it is a button symbol or not, since scenes are usually located at the root, but for your case, it may not be like this because you may have created scenes within another movieclip. So if blue-genie got it working, you should get it working too.

OK, now let's check whether you are referencing the right movieclip when calling gotoAndStop.

To do that, change your code to the code as shown below.
import flash.display.Scene;

for (var i:int = 0; i < MovieClip(root).scenes.length; i++) {
    var scene:Scene = MovieClip(root).scenes[i];
    trace("Root scope:" + scene.name);
}
 
for (var i:int = 0; i < scenes.length; i++) {
    var scene:Scene = scenes[i];
    trace("This scope:" + scene.name);
}


this.navDrop_mc.galleryHM_btn.addEventListener(MouseEvent.CLICK, switchScene);


//function to switch scenes based on which button was selected from dropdown menu
function switchScene (evtObj:MouseEvent):void {
//trace to test function
        trace ("Button was selected from drowpdown menu");
        for (var i:int = 0; i < scenes.length; i++) {
    var scene:Scene = scenes[i];
    trace("Button scope:" + scene.name);
 }
}

If you do not find anything traced out with the name SceneGP, then your scene must be either in another movieclip or you did not even name your scenes correctly or did not rename them, though I think the problem is with the former.
0
 
beemerrider130hpAuthor Commented:
I replaced my code with your sample above. I'm getting compiler errors:

Line 98    1151: A conflict exists with definition i in namespace internal.
Screen-shot-2010-01-06-at-8.54.3.png
0
 
beemerrider130hpAuthor Commented:
That was weird, the rest of my comment disappeared. I'll try again. These are the compiler errors I'm getting from your code:

1151: A conflict exists with definition i in namespace internal.
0
 
beemerrider130hpAuthor Commented:
Okay, not sure what's going on here... maybe it doesn't like that I'm copying and pasting from the error window, but my comments were cut off again when I submitted. I'll try yet again.

I am getting a compiler error referring to the two lines in the code attached below. 1151 A conflict exists with definition i in namespace internal. 1151  A conflict exists with definition scene in namespace internal. Warning 3596 Duplicate variable definition. Warning 3596 Duplicate variable definition.

I'm not sure what you mean when you mentioned my scenes might be in another movieclip. I've got one fla file with six different scenes. I can see them all listed in the dropdown (see my screenshot attachment two comments up). My actionscript is in the main timeline of SceneHM.

I'm thinking maybe it might be a better idea to separate my scenes into different files instead of using scenes... this seems very problematic.
for (var i:int = 0; i < scenes.length; i++) {
   var scene:Scene = scenes[i];

Open in new window

0
 
TanLiHaoCommented:
Sorry it was my mistake,  I was in a rush and I gave all the variables the same name. Here's the new code.

import flash.display.Scene;

var scene1:Scene;
var scene2:Scene;
var scene3:Scene;

for (var i:int = 0; i < MovieClip(root).scenes.length; i++) {
    scene1 = MovieClip(root).scenes[i];
    trace("Root scope:" + scene1.name);
}
 
for (var i:int = 0; i < scenes.length; i++) {
   scene2 = scenes[i];
    trace("This scope:" + scene2.name);
}


this.navDrop_mc.galleryHM_btn.addEventListener(MouseEvent.CLICK, switchScene);


//function to switch scenes based on which button was selected from dropdown menu
function switchScene (evtObj:MouseEvent):void {
//trace to test function
        trace ("Button was selected from drowpdown menu");
        for (var i:int = 0; i < scenes.length; i++) {
              scene3 = scenes[i];
              trace("Button scope:" + scene3.name);
       }
}

Yes I know that you would have named the scenes correctly, but here what I am trying to do is to trace out which is the correct scope to access the scene.
0
 
TanLiHaoCommented:
Oops I didn't see the error with the counter i as well. Again, here's the new code.

import flash.display.Scene;

var scene1:Scene;
var scene2:Scene;
var scene3:Scene;

for (var i:int = 0; i < MovieClip(root).scenes.length; i++) {
    scene1 = MovieClip(root).scenes[i];
    trace("Root scope:" + scene1.name);
}
 
for (var j:int = 0; j < scenes.length; j++) {
   scene2 = scenes[j];
    trace("This scope:" + scene2.name);
}


this.navDrop_mc.galleryHM_btn.addEventListener(MouseEvent.CLICK, switchScene);


//function to switch scenes based on which button was selected from dropdown menu
function switchScene (evtObj:MouseEvent):void {
//trace to test function
        trace ("Button was selected from drowpdown menu");
        for (var k:int = 0; k < scenes.length; k++) {
              scene3 = scenes[k];
              trace("Button scope:" + scene3.name);
       }
}
0
 
beemerrider130hpAuthor Commented:
Thanks. This is what traced:

Root scope:SceneHM
This scope:SceneHM
Button scope:SceneHM
0
 
beemerrider130hpAuthor Commented:
I think I just figured out the problem. I have been 'Testing Scene' instead of 'Testing Movie'. I have duplicate function issues causing compiler errors when I test the whole movie, so I've just been testing each scene at a time for now. This would explain why it can't find the other scenes... I'm not compiling them. I'm sorry you spent all this time on this when it turns out to be operator error.

After so much research about scenes, I think I should probably consider not using them for this project because I think my file size will be too big. If I break each scene apart into it's own fla file, do you know of a good reference where I can find instructions on how to navigate back and forth between them?
0
 
beemerrider130hpAuthor Commented:
Your solution for tracing the scenes led me to discover the true problem. Thank you.
0
 
TanLiHaoCommented:
Hmm, a good reference to navigate back and forth? Nope I don't think so.

It's pretty simple actually, here's a method to do it.

Create a loader in the first frame or document class. Then load a swf in. Once the swf reaches the last frame, call the parent and the parent will load a new swf.
0
 
beemerrider130hpAuthor Commented:
Thanks, got it working
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now