Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Phill

Physics2D, Movieclip instead of dots?

Recommended Posts

Should this not be working?

 

import com.greensock.*; 
import com.greensock.easing.*;
import com.greensock.TweenLite;
import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.Physics2DPlugin;
TweenPlugin.activate([Physics2DPlugin]); //activation is permanent in the SWF, so this line only needs to be run once.

for (var i:int = 0; i < 150; i++) {
tweenDot(getNewDot(), getRandom(0, 3));
}

function tweenDot(dot:Shape, delay:Number):void {
dot.x = 0;
dot.y = 0;
TweenLite.to(dot, 1, {physics2D:{velocity:getRandom(100, 400), angle:getRandom(190, 170), gravity:500}, delay:delay, onComplete:tweenDot, onCompleteParams:[dot, 0]});
}

function getNewDot() {
testClass();
}

function getRandom(min:Number, max:Number):Number {
return min + (Math.random() * (max - min));
}

 

I set up a custom class as I read in another post here, but I don't think I'm implementing it properly. I get this error:

 

1136: Incorrect number of arguments. Expected 1.

 

Can someone help me out? I'm pretty new to AS3 as well.

Link to comment
Share on other sites

I think your getNewDot() function need to have a return type, and your class need to return something too

 

Just change all the :Shape to :MovieClip to use movieclip

 

e.g. function getNewDot():MovieClip { return xxxx }

Link to comment
Share on other sites

Yep, one problem is you're not returning anything with your getNewDot() method (by the way, if you're going to change it to a MovieClip, you'll need to also change the type of the first parameter of tweenDot() from Shape to MovieClip) and I have no idea what your testClass() is expecting - I suspect that is expecting a parameter but you're not passing one.

Link to comment
Share on other sites

Basically I bought Greensock to use this one Phsyics tool to create a rain animation that loops, that part is easy, but getting this to work is beyond me.

 

import com.greensock.*; 
import com.greensock.easing.*;
import com.greensock.TweenLite;
import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.Physics2DPlugin;
TweenPlugin.activate([Physics2DPlugin]); //activation is permanent in the SWF, so this line only needs to be run once.

for (var i:int = 0; i < 150; i++) {
tweenDot(getNewDot(), getRandom(0, 3));
}

function tweenDot(dot:MovieClip, delay:Number):void {
dot.x = 0;
dot.y = 0;
TweenLite.to(dot, 1, {physics2D:{velocity:getRandom(100, 400), angle:getRandom(190, 170), gravity:500}, delay:delay, onComplete:tweenDot, onCompleteParams:[dot, 0]});
}

function getNewDot():MovieClip {

return testClass();

}

function getRandom(min:Number, max:Number):Number {
return min + (Math.random() * (max - min));
}

 

Should that not work? Can someone provide me with working code at all that replaces the dots with a movieclip? Is there any pages / topics that have snippets for things like this that are pre built?

 

Thank you

Link to comment
Share on other sites

NVM I got it.

 

import com.greensock.*; 
import com.greensock.easing.*;
import com.greensock.TweenLite;
import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.Physics2DPlugin;
TweenPlugin.activate([Physics2DPlugin]); //activation is permanent in the SWF, so this line only needs to be run once.

for (var i:int = 0; i < 500; i++) {
tweenDot(getNewDot(), getRandom(0, 3));
}

function tweenDot(dot:MovieClip, delay:Number=0):void {
dot.x = 0;
dot.y = 0;
TweenLite.to(dot, 1, {physics2D:{velocity:getRandom(100, 400), angle:getRandom(190, 170), gravity:500}, delay:delay, onComplete:tweenDot, onCompleteParams:[dot, 0]});
}

function getNewDot():MovieClip {
var e = new Example();
addChild(e);
tweenDot(e);
return e;
}

function getRandom(min:Number, max:Number):Number {
return min + (Math.random() * (max - min));
}

Link to comment
Share on other sites

  • 4 weeks later...

Can you give a little more help here I'm a noobie and want to do the same thing. What do I replace in the function? I'm guessing most people want to use it this way. I'd love some more elaborate docs.

Thanks,

J

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×