Actionscript 3 - Access of undefined property error - actionscript-3

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.

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

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.

Loading movie with a button

I am trying to load movies via buttons interaction with ActionScript 3.0. I am creating this movie from Flash CS 5.5.
I could get the first button (I called 'Preface') to work. When adding the second button, I got this error at runtime:
Scene 1, Layer 'Actions', Frame 1, Line 22 1023: Incompatible override.
Scene 1, Layer 'Actions', Frame 1, Line 22 1021: Duplicate function definition.
There dun seem to be any duplicate that could initiate any overrides:
//import flash.events.MouseEvent;
preface.addEventListener(MouseEvent.CLICK, preface1);
sq.addEventListener(MouseEvent.CLICK, sq);
function preface1(event:MouseEvent):void
{
// Start your custom code
// This example code displays the words "Mouse clicked" in the Output panel.
trace("Mouse clicked");
var preface:Preface= new Preface;
addChild(preface);
preface.removeEventListener(MouseEvent.CLICK, preface1);
// End your custom code
}
function sq(event:MouseEvent):void
{
//Get sample menus
}
Any pointers is highly appreciated.
You have an instance of a MovieClip named sq, and you declare a function with name sq. This is no longer possible to do with Actionscript 3. You have to name your function something other than sq or preface, as this name is occupied by your another MC.

Flash Player 11.2 Video Events addEventListener

Has anyone been able to get an addEventListener working with Flash Player 11.2?
I always get this error:
Scene 1, Layer 'actions', Frame 1, Line 104 1119: Access of possibly
undefined property COMPLETE through a reference with static type
Class.
If I switch my flash player to output to
here is my code:
import flash.events.Event;
import fl.video.VideoEvent;
import fl.video.*;
myVideo.source ="videoName.flv";
myVideo.play();
myVideo.addEventListener(VideoEvent.COMPLETE, vidComplete)
function vidComplete(event:VideoEvent) {
trace("done");
}
For some reason, the AS3 compiler for Flash Player 11 in Flash CS6 seems to ignore the import statements for fl.video.*;
Source: http://forums.adobe.com/message/4699000
This person's solution implies that specifying the entire class package inline in the code as follows should alleviate the issue:
myVideo.source ="videoName.flv";
myVideo.play();
myVideo.addEventListener(fl.video.VideoEvent.COMPLETE, vidComplete)
function vidComplete(event:fl.video.VideoEvent) {
trace("done");
}

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.