hitTestpoint giving error in Action Script 3 - actionscript-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.

Related

Animate Actionscript 3.0 scene not found, but scene exists

My project is an interactive ebook and I created different scenes for each page ( there are 1 to 19 scenes)
I need to insert some ActionScript in order to be able to return to the homepage, and go to some other pages but when I click in the button in the scene, this error keeps showing up :
ArgumentError: Error #2108: Scene Scene 1 was not found. at
flash.display::MovieClip/gotoAndPlay() at
OPP_TCC_fla::MainTimeline/fl_ClickToGoToScene_50()
The code that I have written is :
b_home.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_50);
function fl_ClickToGoToScene_50(event:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(1, "Scene 1");
}
I don't know how to fix that! Any help is appreciated, thanks!
Nope, that doesn't always work either...
ArgumentError: Error #2108: Scene ElDiabloChase was not found.
at flash.display::MovieClip/gotoAndPlay()
at Final_Project_v13b_QuitCode__700X438__EndCredits_fla::MainTimeline/ClickToGoToScene1()[Final_Project
I've literally stooped to the ridiculous task of copying the name from the scene list and pasting it into the code.
If you test the movie in a browser, it'll work most of the time, but in Animate, I can almost never get it to work right.
All I can think is that it's a weird "# of character thing" or something like that. I'm stumped.
Scene List
Like #Organis said in the comment, you have to specify the scene in the second argument.
MovieClip(this.root).gotoAndPlay(1, "Cena 19"); is going to take you to the first frame of Cena 19.
MovieClip(this.root).gotoAndPlay(1, "Scene 1"); is going to take you to the first frame of Scene 1.
See the answer to this question: Action Script - how to go to another scene from movieClip?

Flash CS4 AS3 Event not working

I can't attach a simple event handler to a lousy movie clip. Not a single tutorial worked for me and I followed them carefully. Over an hour wasted for nothing... again! Here's what I did:
Layer1: created a symbol(movie clip). Added a rectangle. Draged it onto the layer. Added a name 'obj' in the Properties window. Exported it for ActionScript.
Layer2: Open Action Panel and wrote the following:
obj.addEventListener(MouseEvent.CLICK, move);
function move(event:MouseEvent):void {
obj.x = 200;
obj.y = 200;
}
I don't know what I might be overlooking. I tried with the import flash.events.Event; at the top. Although it wasn't present in the tutorials I've watched(on youtube).
P.S. Needless to say, I'm just starting with ActionScript 3.0 but I am reading about the basics on adobe.com
I think I got it. Adding a name for the movie clip symbol is one thing. But when we drag it onto the stage, then we have to click it. And THEN, in the properties tab of the object on the scene, we give it a (class) name. So that ActionScript can see and use it. Right-clicking on the movie clip in the Library tab and selecting Properties is NOT the properties we're looking for.
Edit: Thanks, akmozo. I just found that out. Took me long enough!
Edit2: Just wanted to point out something - when I save a project in Flash CS4 which has an event handler. The handler didn't work. The code itself, that is. I tried the same project in CS3 and it worked fine. So part of the problem was the program itself(Flash CS4).

accessing functions between two (2) movieclip inside a nested movieclip AS3

ok im a noob for AS3 since i just started, i have two (2) movieclips inside a movieclip, the main mc is called main_mc then the two movieclips inside named trigger_mc and move_mc, trigger_mc has the instance name of start_ani, then inside the timeline of main_mc i have this code:
import flash.events.MouseEvent;
start_ani.addEventListener(MouseEvent.CLICK, correctans);
function correctans(e:MouseEvent):void {
move_mc.animate();
}
then i created a motion as actionscript 3.0 using move_mc then i inserted the code inside the timeline of the move_mc itself, and i made a function for that motion called animate, my problem is how do i access a function between two movieclips which both are inside another movieclip, i know this method is not programming wise, but i kinda need to learn this, pls help me, i badly need this, thank you in advance.
Parent is a property, not a function - you don't need ():
this.parent.move_mc.animate();
Also, you didn't mention the instance name of the move_mc movieclip, but access like the above requires the instance name to be move_mc - the movieclip symbol name doesn't matter in actionscript.
Update 1: To clarify, you said: trigger_mc has the instance name of start_ani
Good, then this code will work:
start_ani.addEventListener(MouseEvent.CLICK, correctans);
But you didn't say: move_mc has the instance name of ???
So we don't know if this code will work:
function correctans(e:MouseEvent):void {
???.animate();
}
Fill in those ??? for one.
Update 2: do you know if the click handler is being fired? Why not add a trace statement?
function correctans(e:MouseEvent):void {
trace("got click event!");
???.animate();
}
Because for a CLICK event, you need:
start_ani.buttonMode = true;
Though as you say, this isn't good programming practice because this assumes those two movieclips are siblings of the same parent. It's not extensible. If they're not, your code could throw errors. Just keep that in mind.

AS3: Access button from class

So im quite new to AS3 but have worked with AS2 a lot before.
I have created a button and placed it on my stage then inside my class i have added this:
test.addEventListener(MouseEvent.CLICK, buttonClicked);
function buttonClicked(ev:MouseEvent):void
{
trace("Clicked");
}
Now this does not work as it can't find the stage, the only way i can get this to work is if i put the listener on the same frame as the button & not in the class.
But there must be away around this.
Thank you.
Eli
Update - adding Error messages
If I keep the above code all in the external class these are the errors i get.
Line 22 1120: Access of undefined property test. Line 22 1120: Access
of undefined property myButtonClick.
If you have created a document class with timeline then your "test" button must be in first frame. Because document class starts executing from first frame. You can access your button instance only when its available in stage.
Oh, I forgot to mention. You have to declare those instances as public variable in your document class.
public var test:SimpleButton;
Please go thru below and let me know which of the way you were having.
1) Are you having Document class?
There is a field Class in the Document Properties under the Publish tab of the flash IDE, if you are giving your class name in that field then it is called as Document Class
If you are having document class then you can create listener to your button even in the constructor button. Flash won't throw any errors like you got.
2) If you are instantiated your class in the first frame, it won't have the properties of stage till you add that to the stage using addChild. Also it won't have access to your button. And so it will throw the error, The access of undefined property.
Have you assigned the instance of the button on the stage the name "test"? The error message you posted seems to say there is nothing with the name "test" to assign the event listener to.
To check, click on the button the stage and look at the 'Properties' tab: will show in a text box near the top if it needs assigning.
Now the second error you posted means you're referring to something called "myButtonClick" without first declaring/initialising a variable/function with that name. You will either need to declare it or correct it if you meant to refer to something else.
Fixed.
I was being rava stupid as normal, forgot to put them inside the init :|
For the people who might come across this problem.
Working Code:
public function Main()
{
// constructor code
test.addEventListener(MouseEvent.CLICK, myButtonClick);
}
function myButtonClick(ev:MouseEvent):void
{
trace("button Clicked);
}
Anyway thanks guys for the help sometimes its just the simplest answers are the correct ones.
Eli

Actionscript 3: gotoAndStop

I have a project in Flash CS3 that's giving me a bit of trouble. I have a movieclip, and in that movieclip, I have a button. The movieclip is named bg and the button tohallway_btn. My coding is on the stage on a layer, not on classes or in a package, or anything of that sort. This is my coding:
bg.tohallway_btn.addEventListener(MouseEvent.CLICK, tohallwayClick);
function tohallwayClick(event:MouseEvent):void{
gotoAndStop (141);
}
It seems simple enough, yet when I debug and the button is clicked, the flash player freezes over. I have absolutely no idea what's causing it to do this.
I get a type error in output as well:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Camille_fla::MainTimeline/enterF()[Camille_fla.MainTimeline::frame140:130]
Any help is appreciated.
An onEnterFrame listener was called and not removed that was referencing an object (bg) that was not on the stage after the goto call.
function tohallwayClick(event:MouseEvent):void {
**removeEventListener(Event.ENTER_FRAME, enterF);**
gotoAndStop(141);
}
First make sure your button and your code are on the same frame, they can be on different layers, but make sure they are lined up.
If you want it to go to the frame on your main timeline, or stage, instead of writing:
gotoAndStop (141)
try:
stage.gotoAndStop(141);