ActionScripts3 Movie clip click event issue - actionscript-3

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);

Related

Adobe Flash Pro CS6 movie looping after adding code to actionpanel

i have got a problem and cannot figure out. Everything is fine when i test the scene, i have added stop(); to my movie clip timeline and everything is fine until no code is added to the main stage. As soon as i start adding code to the stage, it starts looping? Because of this i'm stuck with a problem and cannot even develop further, because even mouse click events wont work of that looping... The code i am trying to add is just a simple move layer off stage after click on play button:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
introScreen.play_btn.addEventListener(MouseEvent.CLICK, clickAway);
function clickAway(event:MouseEvent):void
{
moveScreenOff(introScreen);
}
function moveScreenOff(screen:MovieClip):void
{
//Move the screen off...
var introTween = new Tween(screen,"x",Strong.easeInOut,screen.x,(screen.width)*-1,1,true);
//When the motion has finished...
introTween.addEventListener(TweenEvent.MOTION_FINISH, tweenFinish);
function tweenFinish(e:TweenEvent):void
{
trace("tweenFinish");
//Establish the game state...
gameState = STATE_INIT_GAME;
trace(gameState);
//Fire off the gameLoop function at the frame rate of the movie...
addEventListener(Event.ENTER_FRAME, gameLoop);
}
}
The reason your animations are looping continuously is because you have errors in your code.
Access of undefined property gameState.
Access of undefined property STATE_INIT_GAME.
Access of undefined property gameState.
Access of undefined property gameLoop.
You are trying to reference members that haven't been created yet or don't exist. Your main timeline starts at frame 1 with the code you referenced trying to access those variables and the gameLoop method. You need to setup the variables in the first frame to allow them to be referenced. i.e. under your import statements:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
var gameState:String;
const STATE_INIT_GAME:String = "GAME_INIT";
then you need to add the gameLoop function:
function gameLoop(e:Event):void {
trace('game loop running');
}
If you don't want those variables and that function setup there then you need to go to the frame using gotoAndStop or gotoAndPlay where those functions and variables can be declared and/or initialized, and stored into memory. Then they will be accessible.

Actionscript 3 - Access of undefined property error

In my timeline, I have a 'background' layer, an 'actions' layer and a 'play' layer (all have just 1 frame). The background layer has a MovieClip called backgroundMC and when you double click the MovieClip, there is a MovieClip called analysisScreenMC. In the timeline for analysisScreenMC, there is a folder called 'Title Bar' and inside 'Title Bar' there is a layer called 'answers' which has a motion tween which makes analysisScreenMC fade out to 50% in a span on 15 frames.
The 'play' layer just has a MovieClip called playButton.
Now, when playButton is clicked, I want to play analysisScreenMC so that it fades out. Here is what I tried.
import flash.events.MouseEvent;
import flashx.textLayout.formats.Float;
function playButtonClicked(evt:MouseEvent):void {
analysisScreenMC.play();
}
playButton.addEventListener(MouseEvent.CLICK, playButtonClicked);
when I run this, it gives me an error saying 'Access of undefined property analysisScreenMC.'
Any idea on how to fix this?
Note: I am using Adobe Flash CS 5 and Actionscript 3.
Edit: When I put
trace("backgroundMC="+ backgroundMC+", backgroundMC.analysisScreenMC="+ backgroundMC.analysisScreenMC);
inside the
function playButtonClicked
this is what it traces
backgroundMC=[object analysisScreenInside_1], backgroundMC.analysisScreenMC=[object MovieClip]
analysisScreenMC is the instance name of analysisScreenInside
Try the following code. I dupcliated your file on my system and this code appears to work just fine.
import flash.events.MouseEvent;
import flashx.textLayout.formats.Float;
function playButtonClicked(evt:MouseEvent):void {
backgroundMC.play();
}
playButton.addEventListener(MouseEvent.CLICK, playButtonClicked);
The key here is that your reference to the location of where analysisScreenMC is located was incorrect.

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.

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.

Flash go to frame label action

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");