Mathematically Modelling a Shape's X-position

  • Y2k88
  • Novice
  • Novice
  • Y2k88
  • Posts: 21

Post 3+ Months Ago

Hello guys...

First post in the flash forum...
Starting with a question which will help me with my first decent Flash project:

I've been given this maths assignment where I have to model three cane toads in a 10 metre race. Each cane toad follow a specific formula:

Cane Toad 1: d = 2.4 + 0.75t
Cane Toad 2: d = 0.4t (t - 7)
Cane Toad 3: d = 0.2t (t - 5)(t - 9)

where 'd' is the distance from the starting line
and 't' is the time in minutes.

Question: Is it possible to write a script in ActionScript so that an image's x-position changes with the different frame numbers?

such as: Cane Toad 2: X-position = 0.4 * frame_no. (frame_no. - 7)

Is that possible?
And can anyone lead me to any websites that can teach me how to do this?

BTW, the i want the frogs to go left to right... if that makes a difference.

Cheers, in advance...

Any help appreciated.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Arkitus
  • Novice
  • Novice
  • Arkitus
  • Posts: 17

Post 3+ Months Ago

Hi there!

This is my first attempt to help someone in flash, so it probably won't be any good!

but heres how i would do it:

create a movie clip, and in the first frame of the movie clip write this:
Code: [ Select ]
onClipEvent(load)
{
    i = 0
}
onClipEvent(enterFrame)
{
    _root.toad._x = i;
    _root.toad._y = 2.4 + 0.75*i;
    
    i++;
}
  1. onClipEvent(load)
  2. {
  3.     i = 0
  4. }
  5. onClipEvent(enterFrame)
  6. {
  7.     _root.toad._x = i;
  8.     _root.toad._y = 2.4 + 0.75*i;
  9.     
  10.     i++;
  11. }

create another movieclip in the library, that looks like the toad. Drag it in the movie clip. call it toad.

then go to the stage, and move the movie clip ( with the toad movie clip in it ) to somewhere in the middle.

It should work, i haven't tested it though.
  • Y2k88
  • Novice
  • Novice
  • Y2k88
  • Posts: 21

Post 3+ Months Ago

Thanks Arkitus,

I'll try that as soon as I can find the time...

I've been swamped with 6 assignments ATM (first week back at school).

Again, thanks for helping me.
  • Y2k88
  • Novice
  • Novice
  • Y2k88
  • Posts: 21

Post 3+ Months Ago

It gave me 2 errors when i tried it:

clip events are permitted only for movie clip instances
onClipEvent(load)

clip events are permitted only for movie clip instances
onClipEvent(enterFrame)

I think i've followed your instructions correctly (i may be wrong)
sorry for the newbiness
  • Arkitus
  • Novice
  • Novice
  • Arkitus
  • Posts: 17

Post 3+ Months Ago

oh, yeah. you're right. put those actions for the toad, not the frame.

ill start making one myself right now... just wait a sec.
  • Arkitus
  • Novice
  • Novice
  • Arkitus
  • Posts: 17

Post 3+ Months Ago

hi

here it is:

http://www.arkitus.com/downloads/toad.fla

or

http://www.arkitus.com/downloads/toad.swf

this is a mx file, i think you can open it.

if not, heres how to do it:

1) Create movie clip called toad 1 in library
2) copy toad 1 into stage
3) create movie clip called toad in library
4) copy toad into toad 1
5) calle the instance of toad, toad. ( in the properties panel )
5) add this code to toad:
Code: [ Select ]
onClipEvent (load) {
    i = 0;
}
onClipEvent (enterFrame) {
    _x = i;
    _y = -(2.4+0.75*i);
    i++;
}
  1. onClipEvent (load) {
  2.     i = 0;
  3. }
  4. onClipEvent (enterFrame) {
  5.     _x = i;
  6.     _y = -(2.4+0.75*i);
  7.     i++;
  8. }



Now you can move toad 1 in the stage to anywhere you want for the origin (0,0).

Note that the use of _y = -(2.4+0.75*i); is because flash has wierd positive/negative schemes :?

Hope that helps

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 8 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.