Using movie clips/symbols in AS3 - access of undefined property - actionscript-3

I'm following (or rather not following!) the tutorial found here: http://www.flashuser.net/flash-tricks/tips-tricks-10-using-drag-drop-in-actionscript-3-0.html
I've drawn a shape (its a rectangle). I've then right clicked and selected "Convert to symbol". Its of the Movie Clip type and its name is item1. (I haven't selected "export for actionscript").
My actionscript on the first frame looks like this... simply:
item1.initX = 0;
This gives the error access of undefined property item1.
I have no idea how to remedy this. Downloading the source from the link appears to be exactly the same as my attempt, yet theirs works.
Any idea why this doesn't work. No other tutorials or help anywhere seems to show my issue. I've tried everything I can think of including checking the "export for actionscript" and all sorts. No luck.
What am I doing wrong? I bet its really really simple! :p
Thanks

You have to instantiate the symbol first.
Select your symbol if it's on the stage, go to the Properties panel, and give it an instance
name : item1 . Here is what the part you've missed in the tutorial : http://screencast.com/t/kk4ZlVl5
If it's not on the stage, you must select "export for actionscript" and instantiate it in your code:
mc = new item1();

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

convert action script 2 to action script 3

OK I read the forums and seems like anyone asking about converting AS2 to AS3 gets flamed with posts like "why would you use AS2, just rewrite it in AS3 from scratch". So please do not answer like this, I just need help figuring out this particular snippet of the code. This is AS2, I have no clue what it is trying to do.
if (_root.components == undefined) {
_root.components = "";
}
_root.components = _root.components + _root.getInstanceAtDepth(this.getDepth()) + " ";
I googled the individual methods 'getInstanceAtDepth' and 'getDepth', and understand they deal with the layering of the movie. Trouble is '_root.components'. If this is referring to a movieclip as 'root', then there is no method or property named 'components'. You can put components on the stage and make them a part of the movieclip fla file but again this does not seem to explain what the code is doing. Does anyone have any idea what _root could be referring to here, what object has a property 'components'?
Thanks,
I think that you want to understand that AS2 code not to convert it.
That code is apparently used inside a component(Button, MovieClip)'s code and it's just trying to concatenate the name of that component to a global string (_root.components).
For example, if I've a button called button and a MovieClip called movieclip, when I execute that code using their onPress() functions, I'll get something like this :
_level0.button _level0.movieclip
Hope that can help.

How to turn a shape into a button AS3

I have started making an advent calendar using the adobe flash professional software. I have drawn each 'door' individually with the draw tool on separate layers. I need to know how to use action script to wait for a click on one of the doors and then goto a specific layer and stop. I have tried different methods such as
button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
but it throws up errors.
Any ideas would be appreciated.
Thanks
If you drew the door it's still just a vector drawing that you can't really do anything with yet - you'll need to convert it to a MovieClip or a Sprite or a Button. The simple way to do this in the interface is:
Use the pointer to select everything you want to be contained in your MovieClip.
Press F8 OR choose "Modify" from the top menu and then "Convert to Symbol."
From there, you'll get a dialog box that looks like this:
You'll need to give it a name. This name will be the Class Name so call it something like "Door" or something descriptive like that. Leave the type as MovieClip and click "Ok."
Now you have the class so you'll have to give it an instance name. Select the object that you just created on the stage. In your properties it should look something like this:
Where it shows "instance name" delete that and give your object a name. In your code example you called it button so call it button here. Now you have an object that can listen for event listeners. Inside your handler you can write something like this.gotoAndStop(2) to get where you need to go.
Hope this helps!

Scoping Dynamically Added Parent Clip

I am totally flummoxed and my eyes are now spinning around in my head. I cannot seem to get this to work.
I have a movie clip that is added as a child of another movie clip. That part works fine.
I want another set of buttons to control what happens inside the newly added clip, but there must be something wrong with my dot syntax.
The button invokes this, MovieClip(this.parent).lightHolder_mc.lightSwitcher_mc.gotoAndStop("red");
and I get:
TypeError: Error #1010: A term is undefined and has no properties. at
testcase_fla::controlpanel_2/makeRedClick()
I've created a ZIP/FLA that strips it down to the bare bones:
http://alphasnail.com/files/testcase.zip
Thanks x1000 to anyone who can help!
I am rather confused why this is not working (the mysteries of Flash, I guess...).
In any case, change it to:
MovieClip(this.parent).lightHolder_mc.getChildByName("lightSwitcher_mc").gotoAndStop("red")