May 21, 2012, 10:54:15 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Prowlie Welcome back! The site migration is complete and normal service resumed.
Advanced search
Pages: [1]   Go Down
Print
Author Topic: Please help me with ActionScript!  (Read 1914 times)
0 Members and 2 Guests are viewing this topic.
Esn
MotM
Heroic
**
Offline Offline

Gender: Male
Posts: 2096


My snake oil is of the highest quality, guaranteed


WWW
« on: December 18, 2008, 10:50:56 AM »

I'm using AS 1.0 (Flash MX).

I'm trying to add snow to my film, and using this actionscript code.  That code can be modified to change the wind speed, # of snowflakes, etc.  I would like to know how to have (for example) few snowflakes and a small windspeed for one scene, and heavy snowfall with a high windspeed in another scene in the same film.  I tried inserting the code modified in two separate scenes, but it seems that I can't do that; it gives me an error.

More details in the last two posts of this thread (I asked this question there, but no-one is answering so far, and I really need an answer soon).

Maybe someone could at least tell me if this is even possible?
« Last Edit: December 18, 2008, 03:45:10 PM by Esn » Logged

<a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf</a>
My blog about Russian animation
My Newgrounds account (animation, art, music)
My DeviantArt account (comics, photos, writing)
Brass ensemble recordings (in which I play tuba & euphonium)
Tophatwonder
Senior Member
****
Offline Offline

Gender: Male
Posts: 627


The tophat of wonders


WWW
« Reply #1 on: December 18, 2008, 02:29:11 PM »

hmm, did the tutorial and had the same problem. it says it needs to appear within a onclipevent handler. i tried fixing it by putting

OnClipEvent(load){
}

above it and putting the } below all the code. it crashed flash and said it was making flash player run slowly and your computer may become unresponsive do you want to continue?

my thaughts on that are, its eaither loading too many flakes to deal with, or..... i don't know lol.  Huh?

sorry.. Sad

wanted to try this out too.


Edit: well it's not the number because i reduced it to 2 and it still was un responsive. i also put the onClipEvent in and added a extra } on the bottom, i only got one error instead of 2, the only error was that i had an extra } in the code, problem is, if i remove it and test movie it crashes and i get the same question.
« Last Edit: December 18, 2008, 02:39:33 PM by Tophatwonder » Logged

Esn
MotM
Heroic
**
Offline Offline

Gender: Male
Posts: 2096


My snake oil is of the highest quality, guaranteed


WWW
« Reply #2 on: December 18, 2008, 02:43:36 PM »

Just to make it a bit easier for people to help me, here is the code that I am using:

Applied to a movieclip on its own layer in the main timeline:

Code:
snowflakes = 30;
do {
   duplicateMovieClip(snow, "snow"+k, k);
   k++;
} while (k != snowflakes);

Applied to a movieclip within that other movieclip (that contains the snowflake - the snowflake can be either a simple white vector circle or a small raster image, which is what I'm using, but the width must equal the height):

Code:
onClipEvent (load) {
//variables
width = 600;
height = 429;
//random x,y, and alpha
this._xscale = this._yscale=50+Math.random()*100;
this._alpha = 20+Math.random()*50;
//random x and y for flakes
this._x = -width+Math.random()*(3*width);
this._y = -10+Math.random()*height;
//speed and trigonometric value
i = 1+Math.random()*2;
k = -Math.PI+Math.random()*Math.PI;
rad = 0;
}
onClipEvent (enterFrame) {
// horizontal movement
rad += (k/180)*Math.PI;
xmovement = width * 0.5;
this._x -= Math.cos(rad)+(xmovement-(width/2))/50;
// vertical movement
this._y += i;
// remove clips when they misbehave (overstep boundaries)
if (this._x>(width+50)) {
this._x = -45;
this._y = Math.random()*height*2;
}
if (this._x<-50) {
this._x = width+45;
this._y = Math.random()*height*2;
}
if (this._y>=height) {
this._y = -50;
this._x = -width+Math.random()*(3*width);
}
}

Note the line xmovement = width * 0.5; : that controls what you might call "wind" "width * 0.5" = 0 wind. Increase the number to increase the wind. Anything less makes it blow the other way. You can put in "-width" to make it blow the other way more strongly.
« Last Edit: December 18, 2008, 02:51:53 PM by Esn » Logged

<a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf</a>
My blog about Russian animation
My Newgrounds account (animation, art, music)
My DeviantArt account (comics, photos, writing)
Brass ensemble recordings (in which I play tuba & euphonium)
Tophatwonder
Senior Member
****
Offline Offline

Gender: Male
Posts: 627


The tophat of wonders


WWW
« Reply #3 on: December 18, 2008, 02:50:03 PM »

I found another tutorial that is pretty much the same as this one, except this one works lol.
http://www.kirupa.com/developer/mx/snow.htm Grin
Logged

Esn
MotM
Heroic
**
Offline Offline

Gender: Male
Posts: 2096


My snake oil is of the highest quality, guaranteed


WWW
« Reply #4 on: December 18, 2008, 02:55:02 PM »

I found another tutorial that is pretty much the same as this one, except this one works lol.
http://www.kirupa.com/developer/mx/snow.htm Grin
What do you mean by "works"?
Do you mean that you can have two modified versions of it in different scenes in the movie, or on different layers in the same scene?

Because the one I'm currently using also "works" for me, but only in one scene; I can't seem to use a modified version of the code for other scenes, or run it in more than one layer (for example, for big, fast snowflakes in the foreground and smaller ones in the background).
Logged

<a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf</a>
My blog about Russian animation
My Newgrounds account (animation, art, music)
My DeviantArt account (comics, photos, writing)
Brass ensemble recordings (in which I play tuba & euphonium)
Tophatwonder
Senior Member
****
Offline Offline

Gender: Male
Posts: 627


The tophat of wonders


WWW
« Reply #5 on: December 18, 2008, 03:04:42 PM »

i don't know, that one you got there doesn't seem to work for me, probably cause i have flash mx 2004, maby mine is to old.
if it works for you great, i was just leeting you know that there was another one out there. Smiley
Logged

Esn
MotM
Heroic
**
Offline Offline

Gender: Male
Posts: 2096


My snake oil is of the highest quality, guaranteed


WWW
« Reply #6 on: December 18, 2008, 03:11:55 PM »

i don't know, that one you got there doesn't seem to work for me, probably cause i have flash mx 2004, maby mine is to old.
if it works for you great, i was just leeting you know that there was another one out there. Smiley
My version of Flash is older than yours; I'm using Flash MX, made in 2002.  Tongue

I wonder if I could use both of these codes, one for "regular snow" and one for "heavy wind snow". Maybe because they're two different codes, they wouldn't give me errors if I used both at once? (or maybe it has nothing to do with that... I really have no idea)
Logged

<a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf</a>
My blog about Russian animation
My Newgrounds account (animation, art, music)
My DeviantArt account (comics, photos, writing)
Brass ensemble recordings (in which I play tuba & euphonium)
Esn
MotM
Heroic
**
Offline Offline

Gender: Male
Posts: 2096


My snake oil is of the highest quality, guaranteed


WWW
« Reply #7 on: December 18, 2008, 07:41:06 PM »

Ok, muddling my way through this, I realized that if I create a new keyframe on the layer of the snow, I can change the code that's attached to snow_mc in the main timeline:
Code:
onClipEvent (load) {
    snowflakes = 200;
    do {
        duplicateMovieClip(snow, "snow"+k, k);
        k++;
    } while (k != snowflakes);
}
So basically, I can change the number of snowflakes in different scenes.

However, I can't change the rest of the code which is contained in the "snow" movieclip that's in the "snow_mc" movieclip, which contains all the other parameters.

Or can I?

...Does anyone know?

The other option is to try to move all of that code inside the mc to just the first frame, so that there's just one section of code, not two. That would mean that I can change the settings as needed.

The Snow 3.0 tutorial from the same site does just that, however, it's made for a much newer version of Flash, and all I have is Flash MX... can the "snow 2.0" code be adapted to also be on just the first frame?

UPDATE: I got some sort of answer over here; now I'm just asking for a clarification...

EDIT: Important question: is there a way to have several keyframes inside a movieclip, and to have instructions in the main timeline saying "stay on frame 1 of the timeline inside the movieclip until frame 200 of the main timeline, then move to frame 2 of the timeline inside the movieclip from frames 201-300"?

EDIT2: Yes, there is a way... I think I'm almost done...
« Last Edit: December 18, 2008, 11:12:39 PM by Esn » Logged

<a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf</a>
My blog about Russian animation
My Newgrounds account (animation, art, music)
My DeviantArt account (comics, photos, writing)
Brass ensemble recordings (in which I play tuba & euphonium)
Esn
MotM
Heroic
**
Offline Offline

Gender: Male
Posts: 2096


My snake oil is of the highest quality, guaranteed


WWW
« Reply #8 on: December 19, 2008, 05:07:50 PM »

Ok folks, I just need one last thing... I'm sorry for posting my questions on two forums (this one and kirupa's), but I'm rapidly running out of time and I really need an answer soon.

I need to get the snow_mc movieclip to move to frame 2 after x frames in the main timeline of film, then onto frame 3 after x frames in the main timeline of the film.

I was told on that forum:
Quote from:
To continually check the _currentframe property, it must be enclosed within an onEnterFrame handler.
Unfortunately, I don't know how to do it properly.

I did try to get the right code for quite a long time, but nothing works. Here's what I have so far, on a frame in the main timeline:
Code:
onEvent (enterFrame)
{
if (!(this._currentframe >= 1 && this._currentframe<=100)){
 snow_mc.gotoAndStop(1);
} else if (!(this._currentframe == 101 && this._currentframe<=200)){
 snow_mc.gotoAndStop(2);
} else {
 snow_mc.gotoAndStop(3);
}
}
However, as far as I can tell, it just stays on frame 1 of the snow_mc movieclip the whole time.

Here is a screenshot of what it looks like, in case my explanation is confusing:
http://e.imagehost.org/0882/screen.gif


I already successfully got it to switch between two frames in the movieclip, but I can't get it to switch between 3 frames.

Here's the 2-frame code that worked:

Code:
if (this._currentframe <= 200){
 snow_mc.gotoAndStop(1);
} else {
 snow_mc.gotoAndStop(2);
}

(snow_mc is the movieclip)
Logged

<a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=november%2006.swf</a>
My blog about Russian animation
My Newgrounds account (animation, art, music)
My DeviantArt account (comics, photos, writing)
Brass ensemble recordings (in which I play tuba & euphonium)
Brackenwood
   

 Logged
Pages: [1]   Go Up
Print
Jump to:  

Theme by Pieter, based on Black Rain by Crip Powered by SMF 1.1.16 | SMF © 2011, Simple Machines XHTML | CSS

Page created in 0.078 seconds with 23 queries.