Adobe flash can't run code in a frame - actionscript-3

Ok, I'm fairly new to Flash, and I was trying to code some ActionScript now for the last two days. I can't a simple piece of code to work:
stop();
So... pretty simple right? ;)
I have a 10 frame animation, and I'm trying to make the animation stop at frame 5. So I select frame 5 from my timeline and then I open the action menu and I simply write stop(); in the window. When I run it I get the following error message:
In ActionScript 3.0 code cannot be placed directly on objects. Please select an object or use the Code Snippet panel to apply code to the current selection on stage.
I totally understand this is a simple question and the answer might be obvious, but I can't find it...
Thanks
EDIT:
I tried debugging it, and it works when in the debugger but not when in flash...

You're putting the code "on" the object, not allowed in AS3 (thx god).
To avoid it, create a new layer and name it "code" (or whatever you want), and put the code in it

Related

Adobe Animate Actionscript 3.0 "clicktogotonextscene" code not working

So I have the following code for a button called "n2" and as you can see it's supposed to take me to the next scene when I click it, but it isn't working. It is inside Scene 2 and I'm trying to get to the next one and whenever I test the scene and click it, I don't even get an error, it just doesn't work.
Btw, it's a GIF defined as a movie clip and then as a button. Could that be causing the problem?
n2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextScene);
function fl_ClickToGoToNextScene(event:MouseEvent):void
{
MovieClip(this.root).nextScene();
}
If you put a trace in the function and comment out "MovieClip(this.root).nextScene();" you could then see if the function gets called on a button click.
I've not used animate before, but in flash you have to name your button/movieclip and then also name the instance. This allows you to create the object twice with two seperate names to be referred to by actionscript.
Not sure if this helps but thought I'd give you some things to try, good luck

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

Error #1009 when the first choice is clicked (but working with the 2nd and 3rd choice)

Ok ive googled about this error and still cant fix my problem.
it was all going well. Im just copying the same codes and changing variable names for the first frame since the 3 frames basically has the same functions. But when i copied it to the first frame, i get that error.
Fla file: https://www.dropbox.com/s/domsbipbxwmyoje/100%20-%20Copy.rar
stop();
small.addEventListener(MouseEvent.CLICK,play1);
function play1(event:MouseEvent):void{
gotoAndStop("3");
}
medium.addEventListener(MouseEvent.CLICK,play2);
function play2(event:MouseEvent):void{
gotoAndStop("4");
}
large.addEventListener(MouseEvent.CLICK,play3);
function play3(event:MouseEvent):void{
gotoAndStop("5");
}
Thats the code for the first frame. Thats just a part of the code and not the whole. I feel like the error is in there. The medium and large are perfectly fine. i carbon copied the codes to the SMALL option but i get an error. I feel like i dont need to post the code for the frame 3 (where the error is happening) since its just the same with MEDIUM and LARGE.
You have to change the name of your button next_btn1 is called in the script but the name on the timeline is next_btn.
Instead of running the movie (ctrl+enter) you can debug the movie (ctrl+shift+enter) try it it will change your life ;)

User interface flash AS 3.0

since the Site seems to be pretty buggy i have to post my question below. Sorry for the inconvenience.
Hi guys
I'm new to flash and i want to create a GUI for my little game.
How can i create a start window where I can select stuff like how many objects to spawn or move speed of my character.
My first idea was to hide everything else on the stage until I click start.
Would that be right. Is the a better way. how to do this anyway.
And where do i put my GUI script. Stage or extern class.
Place your start button in the first frame and put your other elements in second frame. On click of the start button gotoAndPlay to next frame.

How to add an Object to the stage with nested code in AS3.0

I'm busy developing my first application using the AS3.0 language.
I built the full application in Flash Professional, it worked, but it lacked performance.
Now, I'm rebuilding it in Flash builder, so it's more optimised, and it's running great.
Although I've hit a snag.
In Flash Pro, it was very easy for me to add movieclips to the stage, with code nested inside them, so when I added the object, all the code worked like a charm.
In Flash Builder, I have NO clue on how to achieve the same effect... I'm so close to being finished but have no idea how to achieve this.
I've tried making external classes, but with no programming background, it's very hard to find a solution when I don't know where to begin...
SO in short:
HOw to you add objects to your stage using pure AS3 code,
I need to add a graphic object to my stage
And add simple mouse interactivity to it.
Any responses, links, chuckles at me, would be greatly appreciated
Shane
The following code would add a movieclip to the stage, with a line drawn from 0,0 to 100,100 . Provided you are writing this code in the Main class.
var mc:MovieClip = new MovieClip();
addChild(mc) ;
mc.moveTo(0,0)
mc.lineTo(100,100) ;