-1

Completely new to AS3, still learning to ropes, so please bear with me! I am trying to make a game using ActionScript 3.0 that will display 5 grasshoppers jumping around on the stage in random positions. I have tried using TweenLite and TweenMax tweening engines to no avail. It is likely I am doing it completely wrong, but I have no idea where to go at this point. Any help is greatly appreciated.

EDIT: I am trying to put the TweenMax CirclePath2D to affect the individual instances of grasshoppers. I tried putting in the applicable code into the Actions panel itself but it returned with this error: 1020: Method marked override must override another method; and the error 1024: Overriding a function that is not marked for override.

Below is the code I am attempting to use:

import com.greensock.TweenMax;
import com.greensock.easing.*;


TweenMax.to(GrassHopper, 0.25, {bezierThrough:[{x:253, y:139}, {x:272, y:335}], ease:Back.easeIn});

Additionally, I am only using the above locations for now. Is there a way I can randomize where the grasshoppers jump? Additionally, is there any way I can make them continuously hop around everywhere?

Thanks in advance.

  • 2
    TweenLite isn't the only approach, but it would be the approach I would use. Your question is entirely too open-ended right now; basically you're just saying "write my code for me!" You need to ask more narrowly focused questions, like "I attempted to use TweenLite for this task but my grasshoppers aren't moving correctly. Here is the code I wrote, what did I do wrong?" – jhocking Dec 14 '12 at 16:42
  • I added some more information. I hope this provides more insight into my problem. – user1904589 Dec 14 '12 at 17:30
  • That is much better. What is 'GrassHopper'? Is that the name of a MovieClip on your stage, or a class in the library, or what? – jhocking Dec 14 '12 at 17:42
  • GrassHopper is the name of the class. Each instance of the class is grassHopper1, grassHopper2, etc. There are 5 grassHoppers. – user1904589 Dec 14 '12 at 18:31
  • Correction: I am trying to use TweenMax BezierThrough method. However, would CirclePath2D also work? I tried both but got the same errors as listed above. – user1904589 Dec 14 '12 at 18:34

1 Answers1

0

Well first off, you need to refer to specific objects rather than the overall class, so where you wrote 'Grasshopper' you want a reference to grassHopper1. Then loop through all your grasshoppers to set tweens on them.

For randomizing the locations, use Math.random(). So instead of writing x:253 write something like x:Math.random()*253

For continuously hopping around, TweenMax gives an onComplete parameter you can use to call a function when the tween completes. So put onComplete:setHops in the tween and do all the tweening in the setHops() function (ie. have the function call itself)

jhocking
  • 5,527
  • 1
  • 24
  • 38
  • Thanks so much! Where do you think I should put the code? Do I still put the code in the Actions panel or do I put it in my Main.as class? Or, do I put it in my GrassHopper.as class file? – user1904589 Dec 15 '12 at 18:53
  • This did not work; I am still getting the same errors - 1020: Method marked override must override another method; and the error 1024: Overriding a function that is not marked for override. Any ideas? – user1904589 Dec 16 '12 at 11:49
  • Well do you know what overriding a method means? Because if not, well that's what the error says. Also those errors appear to be unrelated to the code you posted; instead of assuming the problem has something to do with TweenLite, you should be trying to figure out what those errors mean. – jhocking Dec 17 '12 at 02:40