Scoping Dynamically Added Parent Clip - actionscript-3

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

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

MovieClip(root.this) not working

I'm having a issue in AS3 with using MovieClip(root.this).
So I have a MovieClip called Slime and I have code inside of slime.idle in the 1rst frame. The code is: MovieClip(root.this).gotoAndStop(2);
For some reason that will not work and does not make the slime go to frame 2. I don't want to do MovieClip(root).gotoAndStop(2); because I have more than 1 slime in the stage that I do not want all of them going to frame 2. That is why I need to use MovieClip(root.this). Does anyone know my problem and how to fix it? Thank you.
MovieClip(root.this) is not valid syntax for multiple reasons. I don't think this behaves how you think; this refers to the object that the script belongs to and cannot be used the way you are trying to use it.
Are you trying to target a specific "slime" to go to frame 2 within its own timeline? In that case you just need to call gotoAndStop() on a reference to that specific slime. For example: MovieClip(root).slime123.gotoAndStop(2). How you get the reference depends on your current code and display structure.
If your code is within the "slime" symbol timeline, you can make it go to frame 2 without referring to root at all, because this is already the target you want. For example: this.gotoAndStop(2) (or gotoAndStop(2); this is usually optional).
If you post more code and explain what you thought this should refer to, I can help more.

AS3 MOUSE_OUT called for a movie clip I just removed

In my current project I'm using few copies of a movie clip that has some buttons on it. One of the buttons is responsible for removing the targeted copy.
It's working well but as the copy disappears it calls the MOUSE_OUT event on itself, and I'm getting Error #1009 as a result.
Found one workaround (I'm killing the copy as a part of MOUSE_OUT event) but it's still not letting me sleep - what is the proper way to handle the situation?
... have you tried clip.removeEventListener(MouseEvent.MOUSE_OUT, yourmouseoutevent);...

Error #1009: Cannot access a property or method of a null object reference

This is quite frustrating. I am simply trying to create a dynamic text and put some text into it on runtime.
I get this error though
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-1()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
I have a text object named textLabel, which is inside a movieclip named MC_state.
I get it because I use:
MC_state.textLabel.text = "asdasd";
And I wish I knew what the problem was. I have other objects set up quite the same way which don't give me that problem. I just don't know how debug that.
Thanks!
The error is telling you that there is no object somewhere along MC_state.textLabel.text, so either flash cannot find MC_state, or textLabelinside MC_state or (unlikely) text inside MC_state.textLabel.
If I may venture a guess though, I think you're seeing this because this happened:
you have somewhere a movieclip called MC_state that has more than one frames. You tied to do gotoAndStop or gotoAndPlay to a frame that has the textfield called textLabel and that's the text you're trying to change.
The problem, and it comes up often for people transitioning from AS2, is that when you execute the gotoAndPlay/gotoAndStop function, the movieClip doesn't update right away, this happens iin the render phase. The code after that function however executes right away, so the movieclip is still at the old frame.
there are two ways you can handle it
set up a event handler that updates the render event, and change the text then. You can hurry the stage rendering by running stage.invalidate example
the other (better) option is to have the text in all the frames, and have it hidden or invisible, that way you can access it at any time.

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

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();