onEnterFrame in Flash 5?

Sunday 1 February 2004

I bought a copy of Flash 5 for my son on eBay, and got him a book about making games with Flash. The book uses Flash MX. I always knew that eventually we’d run across something in the book that needed MX and wouldn’t work with 5.

We ran across it. The something is:

_root.onEnterFrame = myfunc

How do I do this in Flash 5? Please tell me it’s possible.

Comments

[gravatar]
[m] 7:26 PM on 1 Feb 2004

Quick 'n dirty anwser: you can't. That's flash MX syntax.

The good anwser: Don't dispair! You can put that function on an mc, but it has it's disadvantages.

First off, the change in syntax:

_root.onEnterFrame = myFunc;

becomes

onClipEvent(enterFrame) {
//function stuff
}

The disadvantage that this brings is that you cannot overwrite the function, so the mc is stuck with it's original code. Secondly, you cannot put an oCE() on the main timeline (the _root), because it isn't an mc. oCE's are mc's only.

You can overcome this problem, but you need to do some hacking (or going the creative route, that sounds alot nicer). To let the fuction execute on every frame, you need an mc. So let's create one, on the main timeline (also know as the _root). Just leave it empty, you don't need something in there. Now, select the mc and go to the actions panel. Throw in this little piece of code (and the original function):

onClipEvent(enterFrame){
with(_root){
/* this is to make the script happen on the _root, and not
the mc. This could get a little tricky with nested functions,
though */

// the original function goes here

}
}

Even with this little piece of hack you can still run in alot of trouble. FMX has undergone some serious changes compared to F5 so it might be hard to keep up with the book.

If you keep having problems, you can always email me. I'll try to give the best anwser I can. *plug* ;)

This is a fine moment to rave about the evolutionairy supremecy that FMX has over F5, but I'll leave it be. Did I mention there is FMX04 already? ;)

Good luck with flash and I hope your son finds flash a great program, to play and to learn!

PS in the box where you can enter an URL, the www bit throws me off. I thought I only had to enter mantaworks.nl and that the www. stuff would be automaticly appended, but it didn't. Thank you, preview button.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.