-
Statment must appear within on handler error[F8]
Hey all, I'm getting the error "statement must appear within on handler error" with the following code:
Code:
var newgrounds:String = "http://www.newgrounds.com/audio/";
on (release)
{
getURL(newgrounds, "_blank");
anybody know the problem? Thanks for help!
-
Monkey Moderator
when you put code on a movieClip then it must be inside a handler function....
This line...
Code:
var newgrounds:String = "http://www.newgrounds.com/audio/";
.. does not lie inside such a function and so is causing the error.
These days though, it is best practice not to put any code on a movieClip at all.
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
-
can you give me an example of what a handler function is? sorry for my incompetence, I'm very new in this.
Also, my code is on a button, bad practice as well?
Thank you so much for your response and help!
-
Monkey Moderator
your example contained an on handler function.. e.g.
PHP Code:
on (release) { getURL(newgrounds, "_blank"); }
Last edited by Lexicon; 04-14-2008 at 07:21 PM.
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
-
It works!!!!! Thank you so much Lexicon!
-
Monkey Moderator
no worries, enjoy.
Your challenge is to find away of re-writing your code so you don't have to put it on the button. It's very old style to put the code on the button and you'll find it confusing to follow and annoying to edit if you start making bigger projects.
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
-
Error Message : I need Help! :)
Hey Everyone, I cannot figure out what is causing this error message, I thought it was due to the fact that I had not got my "loading random background" to work, but I fixed it and I am still recieving the following message:
Scene=Scene 1, layer=randomjpeg, frame=51, Line 1 Statement must appear within on/onClipEvent Handler
Scene=Scene 1, layer=randomjpeg, frame=51, Line 2 Statement must appear within on/onClipEvent Handler
I know it is directing me to the exact line and frame, but I don't know what to do about it
this is the code I have attached to that frame: I am working in CS5 with AS2.0
choice = Math.round(Math.random()*5);
switch (choice) {
case 0 :
location.loadMovie("image0.swf");
break;
case 1 :
location.loadMovie("image1.swf");
break;
case 2 :
location.loadMovie("image2.swf");
break;
case 3 :
location.loadMovie("image3.swf");
break;
case 4 :
location.loadMovie("image4.swf");
break;
case 5 :
location.loadMovie("image5.swf");
break;
}
Any help would be much appreciated!
-
Senior Member
Can you upload your source FLA? The code works fine in CS6, so i'm guessing the problem is somewhere else.
-
File upload...
It is 183.1 mg it is too big to upload here.
-
Senior Member
Ok took a look at it. It seems that you have actionscript on a MovieClip instance of "randomjpeg" with an instance name of "location" and you have about the same code on frame 51 of the randomjpeg layer.
Any time you put code directly onto a MovieClip, you have to have the code within an on handler like onClipEvent(load){}; but i'm guessing you replaced the code with the code on the frame, if that's the case just delete the extra code.
here is the code from the MovieClip:
Code:
choice = Math.round(Math.random()*6);
switch (choice) {
case 0 :
location.loadMovie("image0.swf");
break;
case 1 :
location.loadMovie("image1.swf");
break;
case 2 :
location.loadMovie("image2.swf");
break;
case 3 :
location.loadMovie("image3.swf");
break;
case 4 :
location.loadMovie("image4.swf");
break;
case 5 :
location.loadMovie("image5.swf");
break;
case 6 :
location.loadMovie("image6.swf");
break;
}
Nearly identical but with case 6. Hope that explanation makes sense.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|