Flash go to frame label action - actionscript-3

It is my first time using AS3.
The way that is set up us I have a "Main MOvie Clip" and inside the main movie clip I have another movie clip which is the MainMenu.
Inside the MainMenu are buttons. The frame label I wanted to go to in outside of the MainMenu but Inside of the MainMovieClip.
I am doing a small project that involves gotoAndPlay("frame label")
In the action layer at the end of the timeline of the MainMenu Moviclip Here is my code:
btn1.addEventListener(MouseEvent.MOUSE_UP,mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndPlay("nordic");
}
stop();
The error I get:
TypeError: Error #1009: Cannot access
a property or method of a null object
reference. at
Ronor_CD20100421_fla::mainMenu_3/frame27()

If the code resides in MainMenu and MainMenu is located in the MainMovieClip you should use:
function mouseDownHandler(event:MouseEvent):void {
MovieClip(this.parent).gotoAndPlay("yourLabel");
}
Cheers

You need to reference the object you want to change. For example:
mainMovieClip.gotoAndPlay("nordic");

Related

ActionScripts3 Movie clip click event issue

I'm trying to write some code for a movie clip to make a clickable area in stage in specific frame, There is an error that i couldn't find what is that error.
"btn_SETTINGS" is a movie clip.
import flash.ui.Mouse;
import flash.events.MouseEvent;
//Stop at frame 72 (STORES PAGE)
gotoAndStop(73);
//Button SETTINGS Click
function goto_SETTINGS(event:MouseEvent):void
{
gotoAndStop(74);
}
trace("button:",btn_SETTINGS);
btn_SETTINGS.addEventListener(MouseEvent.CLICK, goto_SETTINGS);
Error:
button: null
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at APPRAYAN_fla::MainTimeline/frame72()[APPRAYAN_fla.MainTimeline::frame72:13]
Problem is your frame number and code, That function and event listener looking for object "btn_SETTINGS" but there is no object in frame 72, separate your code to different frames.
Frame 72:
gotoAndStop(73);
Frame 73:
//Button SETTINGS Click
function goto_SETTINGS(event:MouseEvent):void
{
gotoAndStop(74);
}
btn_SETTINGS.addEventListener(MouseEvent.CLICK, goto_SETTINGS);

Scrubbing timeline of movieclip that executes actionscript within

I have an as3 script that will scrub the timeline of a movieclip on the stage.
This scrubs the timeline and displays the frame by frame animation but does not execute any actionscript placed on key frames within that movieclip. Users can scrub backwards or forward. I would like to load the script as well as unload depending on the direction the user scrubs. Can this be done?
What you can do is to make new class and extend MovieClip, Inside of that class you can create public methods that you can call from timeline:
public class MyMC extends MovieClip {
public function myMC() {
// constructor
}
public function load():void{
// Do something
}
public function unload():void{
// Do something
}
}
Than if you used "interface" to to add movie clip, click on movie clip and change instance from MovieClip to your class MyMC. Give it also a name (variable name) for example my_mc Than you can call your function from action on timeline
my_mc.load();
my_mc.unload();
Or if you are using just actions to create movie clip you can do like this:
var my_mc:MyMC = new MyMC();
my_mc.load();
my_mc.unload();

How to fix AS3 TypeError: Error #1009: Cannot access a property or method of a null object reference?

I am getting this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Skool_fla::MainTimeline/frame1()[Skool_fla.MainTimeline::frame1:10]
at flash.display::MovieClip/gotoAndStop()
at Skool_fla::MainTimeline/goback()[Skool_fla.MainTimeline::frame2:22]
What is causing this error and how do I fix it?
This is my code for both the frames:
Frame 1: This is the main menu screen where you can access the credit section
import flash.events.MouseEvent;
//setting up the variables
//events
//stop the timeline
stop();
//the play button
play_btn.addEventListener(MouseEvent.CLICK, playani);
function playani(e:MouseEvent)
{
//asking it to progress to the load menu
gotoAndStop(3);
}
//the credits button
credit_btn.addEventListener(MouseEvent.CLICK, creditslide);
function creditslide(e:MouseEvent)
{
//asking it to go the credits frame
gotoAndStop(2);
}
Frame 2: This is where the credits appear
//
//
//all the imports
//events
var credit:credits_bck = new credits_bck ();
var credits_name: credit_nm = new credit_nm ();
var back_butn: back_button = new back_button ();
addChild (credit);
addChild (credits_name);
addChild (back_butn);
back_butn.addEventListener(MouseEvent.CLICK,goback);
function goback(G:MouseEvent)
{
removeChild (credit);
removeChild (credits_name);
gotoAndStop(1);
}
Either play_btn or back_butn is null. Your error message's line numbers don't correspond to your code so it's hard to say. But the gist is you're trying to access a property of something that isn't anything. Check to make sure you're initializing your variables/references properly.
Maybe your problem is Flash bug too.
In my FLA there was a layer with one empty keyframe. If I puted a vector graphics on it, the error was gone. If there was one or multiple MovieClips and there was no vector graphic - the error was there again.
Then I made a new layer and copy pasted all the objects from damaged layer to new and deleted the damaged layer. It solved the problem.
NOTE: Don't copy the keyframes. Only copy the contents.
Now my project is much more complicated and sadly the error came back again.
Test movie frequently and if the error comes back, check the last keyframes and layers you created.

actionscript 3.0 TypeError

Im getting this annoying error and I can`t figure out what the problem might be...
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at simplifyVirSys_fla::copyRightAthenaAcademy_1/initiateApp()
My main time line has two frames:
frame1-the intro and frame2-the application itself
The intro is a movieclip. The code on the last frame of the intro mc goes like this:
addEventListener(Event.ENTER_FRAME, initiateApp);
function initiateApp(e:Event){
MovieClip(root).gotoAndStop(2);
}
So after playing the intro, it should jump to frame 2 of the main time line. And that`s where the output window goes crazy with the #1009 error.
Try this:
addEventListener(Event.ADDED_TO_STAGE, this.ready);
function ready(e:Event) {
removeEventListener(Event.ADDED_TO_STAGE, ready);
addEventListener(Event.ENTER_FRAME, initiateApp);
}
function initiateApp(e:Event){
MovieClip(root).gotoAndStop(2);
}
You can try validating the root.
addEventListener(Event.ENTER_FRAME, initiateApp);
function initiateApp(e:Event){
if (root)
MovieClip(root).gotoAndStop(2);
}
I don't understand why you are trying to go to the frame 2 using an EnterFrame Event. You simply must put a stage.gotoAndStop(2) or MovieClip(root).gotoAndStop(2) in the last frame of you animation.

Flash CS5.5 Output Error

I have been creating a hypermedia player, and i have got to a stage where it is glitching out and it is apparently a...
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AvalancheCityHypermediaPlayer_fla::MainTimeline/fl_CustomMouseCursor()
Here is my code:
import flash.events.Event;
cust_cursor.mouseEnabled= false;
cust_cursor.addEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor);
function fl_CustomMouseCursor(event:Event)
{
cust_cursor.x = stage.mouseX;
cust_cursor.y = stage.mouseY;
}
Mouse.hide();
I am not sure why it is not working properly, basically when a button is hovered over it is meant to jump to frame 2 and stop, but it is jumping to that frame, and then jumping straight to frame 1 without stopping on frame 2, and stops on frame 1.
1 . Your error isn't producing a line number. You (and I) will find this invaluable for debugging; if in the Flash IDE, you can turn this on in the Publish Settings under swf preferences as a toggle titled "Permit debugging".
2 . Is this code inside a class, or in document code (e.g., Flash IDE "Actions" tab)? If it's inside a class, make sure you pass a reference of the stage to the constructor of your class and assign it to an internally persistent variable so that fl_CustomMouseCursor can address it. By default, classes have no internal way of referencing the stage, and I'm assuming that's what's producing your #1009 error.
For example, inside your class constructor...
package com.example {
public class MyClass {
private var stage;
public function MyClass(arg) {
stage = arg;
}
}
}
And outside when instantiating the class...
var myObj:MyClass = new MyClass(stage);
3 . If you want your code to stop on a frame, use stop(); or gotoAndStop()
4 . Finally, if you're compiling with Flash IDE, you can debug this and see exactly which variable in the stack the runtime environment is having issues with. You can access it from the debug menu or by compiling with control-shift-enter.