Animate Actionscript 3.0 scene not found, but scene exists - actionscript-3

My project is an interactive ebook and I created different scenes for each page ( there are 1 to 19 scenes)
I need to insert some ActionScript in order to be able to return to the homepage, and go to some other pages but when I click in the button in the scene, this error keeps showing up :
ArgumentError: Error #2108: Scene Scene 1 was not found. at
flash.display::MovieClip/gotoAndPlay() at
OPP_TCC_fla::MainTimeline/fl_ClickToGoToScene_50()
The code that I have written is :
b_home.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_50);
function fl_ClickToGoToScene_50(event:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(1, "Scene 1");
}
I don't know how to fix that! Any help is appreciated, thanks!

Nope, that doesn't always work either...
ArgumentError: Error #2108: Scene ElDiabloChase was not found.
at flash.display::MovieClip/gotoAndPlay()
at Final_Project_v13b_QuitCode__700X438__EndCredits_fla::MainTimeline/ClickToGoToScene1()[Final_Project
I've literally stooped to the ridiculous task of copying the name from the scene list and pasting it into the code.
If you test the movie in a browser, it'll work most of the time, but in Animate, I can almost never get it to work right.
All I can think is that it's a weird "# of character thing" or something like that. I'm stumped.
Scene List

Like #Organis said in the comment, you have to specify the scene in the second argument.
MovieClip(this.root).gotoAndPlay(1, "Cena 19"); is going to take you to the first frame of Cena 19.
MovieClip(this.root).gotoAndPlay(1, "Scene 1"); is going to take you to the first frame of Scene 1.
See the answer to this question: Action Script - how to go to another scene from movieClip?

Related

How do you move to another scene in actionscript 3 using buttons

I'm trying to use a button to skip from one scene to the first frame from the next scene in Flash CS6, however I keep getting the
error 2108: the scene was not found.
stop();
btnNext.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextScene);
function fl_ClickToGoToNextScene(event:MouseEvent):void {
gotoAndPlay(1, 'scene2');
}
This is my code and ''scene2'' is spelled right, how can I correct this?
Checking the API for gotoAndPlay(), it is an overloaded argument which accepts either a String for the label, or an int for the frame. Furthermore, if a second argument is provided, it points to the frame number in the target scene. A Scene should not be confused with a frame Label. Scenes are like multiple MovieClip timelines, each with their own first frames. According to Adobe,
Using scenes is not the best approach because of a number of drawbacks...
If you are using the automatically generated names, then it should be Scene 2, and not scene2. Furthermore, although your command will work, it will appear to have done nothing unless you also add stop() to the first frame of your new scene.
Alternatively, you could just switch to the gotoAndStop() which won't cause your playhead to jump back to the first scene.
gotoAndStop(1, "Scene 2");

AS3 movie instance turning null

I'm banging my head on what seems like a simple as3 problem. I have a flash chart that contains a series of buttons that go to different parts of the timeline on Roll_over.
so for example - the "Market maneuvers" button looks like this
marketManeuversButton.addEventListener(MouseEvent.ROLL_OVER, marketManeuversButtonReaction)
and the function it calls looks like this
function marketManeuversButtonReaction (event:MouseEvent):void{ gotoAndStop('18'); }
The problem is, when I mouseover that button (and many others), it goes to frame '18' and then throws this error:
Error #1009 Cannot access a property or method of a null object
reference
here is my flash file
Any help would be appreciated. Thanks.
When you change frame, flash recreated all objects in frame, and you loose all your data.
Yes, it's simple AS3 problem, just don't use a scene frames at all. Program all in classes, don't use any frames to code any logic except stop(), gotoAndStop(), gotoAndPlay().
In your problem, put all scene in movieclip, exclude control buttons from it to another movieclip and control scene movie clip with control movieclip >____<. It pegleg. Next time just do it right, don't use scene frames.

ActionScript 3: eventlisteners give 1009 error when not in frame1

Thanks for the responses
*Note when the buttons and code are on Frame 1 it works perfectly *
All the script is in Frame 2, as are the two buttons. The only things not in frame to are the sprites I'm calling out of the library.
Ideally On frame 1 are navigation buttons - each button with a gotoAndPlay() call attached. When you click each one of these navigation buttons it takes you to a different page.
Each page has a a bunch of buttons. Each button, when clicked, plays a an audio, and adds/deletes children to the stage
My problem is any frame other than 1, (in this case 2) as soon as it lands on the frame even with appropriate buttons present it says it doesn't see them and balks at the even listeners.
I hope this makes sense.
----- Original post --------
I'm trying to understand how these things work. I have an empty frame in frame one. In that frame I have the code:
gotAndStop(2);
On frame 2 I have two buttons. I've added event listeners to them. This works fine. The problem is as soon as it hits frame two I get this error :
TypeError: Error #1009: Cannot access a property or method of a null
object reference. at TesT_2_fla::MainTimeline/frame2()
The confusing thing is, when I have everything in Frame 1 it works like a charm.
On frame 2 the buttons are there already, if I put them in frame 1 it works, but in frame 2 no dice.
Can anyone explain what is happening and how I might be able to remedy this?
Not sure why you are writing the script in Frame 1. If nothing were in Frame 1, the user would automatically go to Frame 2, if you placed a stop(); on Frame 2. If you want to stop(); on Frame 1, you could add a button gotoAndStop(2) with an event listener. When placing script on a frame that may be also referenced in a later frame, use a separate script layer and extend that layer from the (key)frame on which the script first appears to the (key)frame on which it is also referenced. HTH
Ya know - after much searching I found a solution it does seem awfully cumberome. I added the following code (which I copied from someone elses post) Just in case any other noobs have a similiar problem
enter code here
//listen for the Flash player's ENTER_FRAME event...
this.addEventListener(Event.ENTER_FRAME, onEnterFrame, false);
//and call this checker function continually until all of the buttons are accounted for
function onEnterFrame(e:Event):void
{
if(and_btn != null && big_btn != null )
{
and_btn.addEventListener(MouseEvent.CLICK, fAnd);
big_btn.addEventListener(MouseEvent.CLICK, fBig);
//clean up the enter frame listener so that this function no longer gets called
this.removeEventListener(Event.ENTER_FRAME, onEnterFrame, false);
}
}
It seems the code was running so fat the buttons didn't have a chance to populate the stage

AS3: Getting information from an externally loaded SWF

So I have an SWF that I've made and I need to appened some instructions to the beginning of the project. I figured the easiest way to do this was to make the animation in a separate SWF then import it to the start of the first one. My problem is that I can't find a reliable way to tell when the first SWF is finished playing. I've googled the heck out of this but I can't seem to find anything that works. For some bizarre reason, no matter what I do the program seems to think that the external SWF only has 2 frames, if I put an ENTER_FRAME listener and trace externalSWF.currentFrame I get "1, 1, 2, 2, 2, 2, 2, 2..." My code looks something like this.
var ldr = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
ldr.load(new URLRequest("Instructions.swf"));
function loaded(e:Event){
trace("Loaded");
var extSwf = ldr.content as MovieClip;
addChild(extSwf);
trace(extSwf.totalFrames);//Returns 2
}
Has anyone else had similar problems with external SWFs?
Also, for the record, the external SWF plays properly when I add it as a child. The problem is removing it from the stage when it's done playing. It's interactive so I can't just do a frame count.
Edit: So I tried doing a getQualifiedClassName() call on extSwf and I got "Instructions_fla::MainTimeline_Preloader_" which could explain the frame discrepency. How can I have access to the actual timeline?
To SWFs can communicate with each other via SharedObject.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html
So I found the solution to the problem. Like I said in the edit, I was getting "Instructions_fla::MainTimeline_Preloader_" as the QualifiedClassName so I googled that and found someone saying that Flash CS5 exports your SWFs with a preloader by default so that was what was being attached to extSwf and not the MovieClip itself. The way to fix it is to go into File>Actionscript Settings>Library Path, and change Default linkage to "Merged Into Code". This appears to only happen in CS5. I found the solution here: http://blog.flash-core.com/?p=142

AS3 preloader sorrows, unable to load symbols from library

I created an AS3 preloader, and placed the code for that on frame one.
I then made a symbol, and placed it in the library. It was set to NOT export on frame 1, and the fla's settings had all classes exported on frame two. There were no references to the object until frame two.
Then, flash crashed whenever I compiled without the "Export in frame one" box checked.
To fix this, a friend suggested I start my game logic on frame 3, so it will have properly loaded frame 2. That seemed to work fine, the class was instantiating properly.
Then, it turned out that it was not loading the movieclip, only instantiating the class. Again, this could be fixed by exporting in frame 1, but I really cannot afford to do that.
The same friend suggested I place an instance of the symbol on the stage on frame 3, and perform game logic on frame 4. They said this would initialize the movieclip properly.
However, this was not the case. How can I load the entire symbol, graphics and all, without exporting to frame 1? This single symbol will contain probably 10-20 MB of graphics, so it needs to be preloaded.
Thanks for the help!
EDIT: To make a long story short, all I need is some way to load a movieclip so it can be used and visible and everything.
EDIT: Is there any way to force-load a movieclip via AS3?
Hard to figure out from descriptions.
If you make a new .fla file, paste your large(10-20MB) clip on frame 2,
set your export frame as 2, then try to preload from frame 1 and access the large clip's content in frame 2, do you get the same error ?
say you have this in frame 1:
stop();
this.loaderInfo.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void{
gotoAndStop(2);
}
and in frame 2:
trace(myLargeClip);//where myLargeClip would be your 10-20MB clip
It should be ok, otherwise, in case tracing your large clip returns null, you might want to try to invalidate the stage:
on frame 2:
stage.addEventListener(Event.RENDER,onRender);
stage.invalidate();
function onRender(event:Event):void{
trace(myLargeClip);
}
Basically what I'm suggesting is:
Isolate the problem. See if your large clip is causing problems in a similar, but simplified scenario and why, then once you got a fix use it in your main fla.
Try the stage invalidation, although, since I don't fully understand your setup, it's just a wild guess.
HTH,
George