AS3: How do I reference a Scene in code? - actionscript-3

I have objects in the main scene and I wish to reference them on a movie clip.
If it was the other way around, I could do
Movieclip.button_btn(...)
What is the equivalent to do that but with a Scene?

I found the answer myself.
For anyone trying to find it, it's Object(root). In this case it would be
Object(root).button_btn(...)

Related

Adobe CS5/AS3 - No "Actions - Movie Clip" tab for my movie clip

I'm writing an Escape the Room game in Flash CS5 / Actionscript 3 (I've written several before) and I have a problem that I've never encountered before. I have two movie clip objects on my escape door movie clip. A doorknob and a keyhole. The doorknob has an "Actions - Movie Clip" tab but the keyhole only has an "Actions" tab with the message "In ActionScript 3.0, code cannot be placed directly on objects. Please select a frame or use the Code Snippets panel to apply code to the current selection on stage."
The two movie clips (instances of two graphics) are in the exact same layer and frame and have identical properties.
I know I'm missing something obvious here and any help would be greatly appreciated!
Adding some screenshots to illustrate:
As you can see below, Doorknob is in the items layer and has an "Actions - Movie Clip tab".
Doorknob
Yet, as you can see below, Keyhole, in the same layer, only has an "Actions" tab.
Keyhole
They are both movie clips.
Thanks!
My mistake, my previous games were using AS2. I will publish this one with AS2 and I will need to learn AS3 going forward, thanks to everyone who read my question and for Organis's reply.

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

AS3 movie instance turning null

I'm banging my head on what seems like a simple as3 problem. I have a flash chart that contains a series of buttons that go to different parts of the timeline on Roll_over.
so for example - the "Market maneuvers" button looks like this
marketManeuversButton.addEventListener(MouseEvent.ROLL_OVER, marketManeuversButtonReaction)
and the function it calls looks like this
function marketManeuversButtonReaction (event:MouseEvent):void{ gotoAndStop('18'); }
The problem is, when I mouseover that button (and many others), it goes to frame '18' and then throws this error:
Error #1009 Cannot access a property or method of a null object
reference
here is my flash file
Any help would be appreciated. Thanks.
When you change frame, flash recreated all objects in frame, and you loose all your data.
Yes, it's simple AS3 problem, just don't use a scene frames at all. Program all in classes, don't use any frames to code any logic except stop(), gotoAndStop(), gotoAndPlay().
In your problem, put all scene in movieclip, exclude control buttons from it to another movieclip and control scene movie clip with control movieclip >____<. It pegleg. Next time just do it right, don't use scene frames.

How to put code onto objects in as3

I am trying to create a kind of simple game where you move a player around and dodge some enemies. I was wondering if it was possible to add code onto a object in as3.
I want to be able to put code onto an object and not on the main timeline, so when it is on the stage, it will carry out the codes.
Sorry if this is confusing, I don't know how to explain it.
Each MovieClip object has its own timeline. Create a layer for code in your object's timeline and add actionscript in the usual way to it -- using the Actionscript panel.
You can start with a simple 'trace' statement to see that it works.
Please do not put code on the timeline.
Read a tutorial about Object-Oriented Programming in AS3. Learn about Document Classes and how to attach a class to a library object.
Here's a link to one of the first tutorials that popped up when I googled "Flash oop tutorial": http://code.tutsplus.com/tutorials/as3-101-oop-introduction-basix--active-5789

How to repeat a movieclip again before it stops

I know this question has been asked before but as a noob i did not understand the answer so im hoping someone can explain a little more for me.
I have an arrow animated along a path using a motion tween I want when a button is clicked for an endless stream of arrows to follow the path, this would be easy if you could put more than one object on a motion tween but you cant? Can anyone help with the code id need to make this happen.
Is there a way to repeat the movieclip again before its finished to give this effect?
Do you have any code, or example of exactly what you're trying to accomplish?
You can use multiple instances of the same movie clip... So (for the sake of explanation) you could animate your arrow once, make sure it's its own movieClip, put it on the stage, and test your movie...It will loop over and over. You can drag as many instances of this movie on to the stage and they will all play, over and over until it's told to stop.
If you need ALL of the arrows to be one movie clip, as to be one addressable object, you can simply select all of your positioned arrows, and convert those into one movieClip (right click, convert to Symbol)
Of course all of this can be controlled precisely through code, but need to know a bit more about what you're trying to do. hope this helps a little...
The function play() will loop your movie forever, unless you have a stop() function somewhere.
yourMovie.play();
If you want to "repeat" / "reset" a MovieClip at any time, use gotoAndPlay() :
yourMovie.gotoAndPlay(1);
If you want to verify if you are at the end of your clip, use the properties currentFrame and totalFrames :
if (yourMovie.currentFrame == yourMovie.totalFrames)
{
// ex. if you want to stop
yourMovie.stop();
}
Ref : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html
Hope that help. Be more specific, if it doesn't answer your question.