Log in

View Full Version : onClipEvent from timeline syntax?



jlizarraga
02-09-2009, 06:58 PM
Hi all,

I'm having trouble with using "onClipEvent(load)" from the timeline. If I put the following on a movie clip (instance name is "newOffers") directly, it works:


onClipEvent (load) {
trace(this._name);
}

But from the timeline, I get the error "Expected a field name after '.' operator" with both of the following:


_root.newOffers.onClipEvent (load) {
trace(this._name);
}

_root.newOffers.onClipEvent (load) = function() {
trace(this._name);
};

The following does not produce an error, but the trace doesn't run either:


_root.newOffers.onLoad = function() {
trace(this._name);
};

I have a basic understanding of the differences in onLoad, onClipEvent(load), the movieClipLoader class, and the loader component, and I'm pretty sure onClipEvent(load) is what I want. I just want to run some AS on that MC one time, at the start of the movie, without running into timing issues where the code is executed before the MC is ready to receive it.

Any help greatly appreciated - this is a frustrating one. :(

Medyman
02-09-2009, 07:27 PM
The onClipEvent(load) syntax only works when attaching actions directly to movieclips. For various reasons, this isn't recommended (Google around for the reasons, or ask :)).

It looks like you're loading in a movieclip using the MovieClipLoader (MCL) class. You didn't provide your code for the MCL class so I'm assuming you haven't called MCL right.

Watch this (http://gotoandlearn.com/play?id=27) tutorial by Lee Brimelow and see if it sheds any light on what you're trying to do. If not, post back.

jlizarraga
02-09-2009, 07:35 PM
Actually, I'm not using the MovieClipLoader class. The only external content I'm loading is some XML, but I'm not having any issues there.

The "newOffers" MC was manually dragged out onto the stage and given an instance name. It's not going to have any content loaded into it or anything like that. All I want to do is set its _visible property to false when the movie starts. I think I'm just overcomplicating the whole thing. :\

Medyman
02-09-2009, 07:37 PM
Actually, I'm not using the MovieClipLoader class. The only external content I'm loading is some XML, but I'm not having any issues there.

The "newOffers" MC was manually dragged out onto the stage and given an instance name. It's not going to have any content loaded into it or anything like that. All I want to do is set its _visible property to false when the movie starts. I think I'm just overcomplicating the whole thing. :\

Hmm...then I'm totally confused as you're trying to do.

If the MC exists on the stage at the start of the movie, you just need to add this to the first frame:


newOffers._visible = false;

jlizarraga
02-09-2009, 11:08 PM
I was under the impression that while that works, there are situations where you might encounter timing issues because sometimes the Actionscript is executed before the target instance is ready to receive commands. Is that not the case? Is it totally safe to use your example?

Like in Javascript, how a script will fail if it tries to access something before it has been rendered.

Medyman
02-10-2009, 12:04 AM
I was under the impression that while that works, there are situations where you might encounter timing issues because sometimes the Actionscript is executed before the target instance is ready to receive commands. Is that not the case? Is it totally safe to use your example?

Like in Javascript, how a script will fail if it tries to access something before it has been rendered.

If the movieclip is on the stage, it will always work. That slight time lapse occurs when you're programmatically applying actions to movieclip instances that are also programmatically generated. If something is on the stage, it's there from the begging of the SWF to the end (unless you explicitly remove it via AS, of course).

jlizarraga
02-10-2009, 12:20 AM
Thank you very much Medyman. So damn, I really was overcomplicating it quite a bit. :D

Edit: Just to be thorough - what if I *had* generated the MC from the library instead of having it on the stage from the get-go? Would one of the things that I was trying then work?