AS3 Error: Access of undefined property Event - actionscript-3

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

Related

add as3 in frames i add in 1 frame for all time line or key frame by key frame?

//this is in frame 1 to put function to movie clip in frame 3
directorio.addEventListener(MouseEvent.CLICK, exec);
function excec(e:MouseEvent):void{
trace("yes");
}
but if i have the same movieclip in frame 2 and 3 i need duplicate the same code.
how i can put a general code in frames?
i have 13 frames and i have problem to add as3 in frames because if i add functions frame by frame i have error of duplicated functions and if i add as3 in onli one frame for all time line i have error of propierty undefined and this already existst -> is movie clip in time line frame 3 example.
so wath is correct? :(
thanks.
1) Search the web about how to create a document class in AS3
2) Create document class
3) I'm not sure what directorio is...but if it is an object go to step 4
4) Search the web on how to create a linkeage class for a library object in AS3
5) Create the linkeage class named Directorio
6) Write the following code inside your document class (name is DocumentClass)
import flash.display.MovieClip;
import flash.events.MouseEvent;
public var directorio:Directorio;
public function DocumentClass()
{
directorio = new Directorio();
directorio.addEventListener(MouseEvent.CLICK, exec);
}
public function exec():void
{
trace("yes");
}
What you're doing is a little like the United States is doing with their debt...instead of thinking of the future of your programming in AS3, you want to make a quick fix for the here and now, sacrificing everything for later. I highly suggest you go through these steps on how to learn to properly code in AS3, rather than a more succinct fix (which is possible, but I won't say how, as I think using classes is very important in AS3). Hope that helps

hitTestpoint giving error in Action Script 3

I am trying to get hitTestPoint to work. When I type this in, I get this error:
Scene 1 1046: Type was not found or was not a compile-time constant: mcircle.
Here is the code I have:
import flash.events.Event;
addEventListener(Event.ENTER_FRAME, hitTest);
function hitTest(evt:Event){
if(mcircle.hitTestPoint(mouseX, mouseY, true)){
hitText1.text= "hitTestPoint- TRUE";
}
else{
hitText1.text= "hitTestPoint-FALSE";
}
}
I am a really new to flash, so I know I am doing some silly mistake. Any help will be really appreciated :)
Make sure that your instance name for mcircle matches your code exactly.
In the flash IDE, click on your circle on the stage so the clip is selected. Then view the properties panel and verify the Instance Name of your clip.
If you are not sure where the properties panel is, you can use the menu at the top of the screen to find it, by choosing Window/Properties.
The name you see in the library, is the name of the symbol. It is not the instance name.

1180: Call to a possibly undefined method DisplayObject

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.

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.

write inline code within documents that has a class assigned

I download an AS3 package and I'm trying to add an eventListener to it. I'm adding this event in inline code. But I get the following error:
1046: Type was not found or was not a compile-time constant: MouseEvent.
Since I don't know how to write classes, my question is: Can I write inline code when the document has a class assigned to it? If so, why am I getting the above error?
Did you
import flash.events.MouseEvent;
?