1180: Call to a possibly undefined method DisplayObject - actionscript-3

A few days back I created a simple point and click game and the following error occurred
1180: Call to a possibly undefined method DisplayObject.
This is my code:
poster.addEventListener(MouseEvent.MOUSE_DOWN, clickposter);
stop();
function clickposter (event:MouseEvent):void
{
removeChild(DisplayObject(event.target));
}
Now the weird thing is, this code worked fine at first but as soon as I added a document class to my project it stopped working and gave me the 1180 error.
My document class is nearly empty:
package
{
import flash.display.MovieClip;
public class Main extends MovieClip
{
public function Main()
{
}
}
}
I have searched around a bit but wasn't able to solve this error.

Importing DisplayObject into your document class will fix this:
import flash.display.DisplayObject;
I'm afraid I don't know exactly what causes the issue as the code for the poster object is separate to the document class code (I assume), sorry it's not the most informative answer but it'll get your code working at least.

Related

AS3 Error: Access of undefined property Event

I'm making a game in Flash CS4 using AS3 and I've been trying to make a Play button that works. I already know how to make it work but while debugging I always get "Access of undefined property Event" in compiler errors.
Here's my code:
// imports
import flash.events.Event;
import flash.events.MouseEvent;
// code
stop();
pbtn.addEventListener(EVENT.CLICK, startPlay);
function startPlay(event:MouseEvent):void
{
gotoAndStop(2);
}
I already set the instance name of the button to "pbtn" so it can't be that. I tried both MouseEvent and just Event for the startPlay() function.
I know this must be a really dumb question but I just can't manage to fix this.
pbtn.addEventListener(EVENT.CLICK, startPlay);
Just change that line to this
pbtn.addEventListener(MouseEvent.CLICK, startPlay);
And its case sensitive so don't change any letter case

Actionscript3 Main class is the root, but does not allow the Animate Virtual Camera

I've recently started learning Animate CC with Actionscript 3.
I'm trying to use Animate's "Virtual Camera" feature, giving me a camera that can pan, rotate, and zoom the game.
It's easy to implement a Camera when the root has no subclass. For example, you can put a block on screen, and add a camera effect within the timeline itself, and play your movie it. Easy.
But when I give the fla a class ("Main") and give that class an external AS3 file, I get an error:
Specific image showcasing what I mean about giving FLA a class
The code below is "Main.as"
package {
import flash.display.MovieClip;
import flash.display.DisplayObject;
import fl.VirtualCamera;
public class Main extends MovieClip {
var camera;
public function Main() {
// constructor code
camera = VirtualCamera.getCamera(root);
trace(camera);
}
}
}
Now, even when I had absolutely no code (other than functional necessities) in Main.as, and a Camera in the timeline, I would get this error:
ReferenceError: Error #1069: Property ___layerDepthEnabled___ not found on Main and there is no default value.
at privatePkg::___Camera___/cameraControl()
I added in this code above to Main, and I get the same error.
The only thing that fixes it is changing
camera = VirtualCamera.getCamera(root);
to:
camera = VirtualCamera.getCamera(this.parent);
and that, while eliminating the code, also doesn't actually give me a camera to use.
How can I use a Virtual Camera and still have Main.as?
Thanks,
Andy
Try declaring public dynamic class Main because it is not impossible that VirtualCamera class is expecting a generic MovieClip as root (which is dynamic = you can add any property without raising an exception).

Alert.Show() null reference as3

I simply want to popup an Alertbox in AS3. I am using Flashdevelop and I got the null reference error when I just run this simple code. I THINK that it has something to do with the stage, but I don't know.
import mx.controls.Alert;
public class Main extends Sprite
{
public function Main()
{
Alert.show("hello World","title",Alert.YES | Alert.NO);
}
}
I would like to run this alert and depending what the Alert returns I would love to return a true or false. But I would be glad if we can start with the displaying of the alertdialog
Alert is a flex component. Are you sure you are creating a flex application?
The problem was, that I wrote all my text in the AS files. When I used an MXML file as view, the alert will pop up correctly.

Having a nightmare with AS3 classes and using them

I really thought I understood the whole AS3 class thing but I have been having a major problem with the most simple of tasks and it is killing me!
Basically, I have my Document Class and am trying to create an object of another class. Both files are in the same folder.
I am currently using:
var sForest:simpleForest = new simpleForest();
In the hope of referencing a class that has this code (I took out everything it does and it still has the same problem):
package ActionScript
{
public class simpleForest {
public function simpleForest() {
trace ("hi!");
}
}
}
And I keep getting these errors:
1046: Type was not found or was not a compile-time constant: simpleForest.
1048: Method cannot be used as a constructor.
I know I am missing something small and stupid but I can't figure it out at all!

1119:Access of possibly undefined property Click through a reference with static type Class

I am making an edutainment game using flash cs5, I'm really new at using flash, in fact we never yet tackle it at school, but I insist on learning about it.
In my codes, I encountered this error
C:\Users\acer\Desktop\JikanLibrary\Main.as, Line 16 1119: Access of possibly undefined property Click through a reference with static type Class.
This is the code I used in my program
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Main extends MovieClip
{
var startPage:StartPage;
var jikanBookshelf:JikanBookshelf;
public function Main()
{
startPage = new StartPage;
jikanBookshelf = new JikanBookshelf;
startPage.jikanBookshelf.addEventListener(MouseEvent.Click, onJikanBookshelf);
addChild(startPage);
function onJikanBookshelf(event:MouseEvent):void
{
addChild(jikanBookshelf);
removeChild(startPage);
}
}
}
}
The error is in this line
startPage.jikanBookshelf.addEventListener(MouseEvent.Click, onJikanBookshelf);
Since I'm really new at flash, I really don't know what went wrong with my codes, it was working a while ago before I put the mouse event. I hope someone could help me.
ActionScript is a case sensitive language. This means that Click is not the same as CLICK. So what you need here is MouseEvent.CLICK
"Why is CLICK all uppercase? Most property names aren't.", you might ask.
That's because CLICK is a static constant property of MouseEvent and the convention amongst ActionScript (and many other languages) programmers is that static constants are written in all uppercase to distinguish them visually from other variables.
'static' means it's a property of the MouseEvent class, not of an instance of MouseEvent.
'const' means it's not a variable: you can't change it's value.
It's a name conflict problem: The class definition name is same as the object name.
The problem in your script is that you have a class definition name startPage and you are trying to create an object of same name startPage.
You have to change the object name to something different. Let say startpage1.