# Mathematically Modelling a Shape's X-position

• Novice
• Posts: 21

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.

Any help appreciated.
• Novice
• Posts: 17

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 ]
{
i = 0
}
onClipEvent(enterFrame)
{

i++;
}
2. {
3.     i = 0
4. }
5. onClipEvent(enterFrame)
6. {
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.
• Novice
• Posts: 21

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.
• Novice
• Posts: 21

3+ Months Ago

It gave me 2 errors when i tried it:

clip events are permitted only for movie clip instances

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
• Novice
• Posts: 17

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.
• Novice
• Posts: 17

3+ Months Ago

hi

here it is:

or

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
5) calle the instance of toad, toad. ( in the properties panel )
Code: [ Select ]
i = 0;
}
onClipEvent (enterFrame) {
_x = i;
_y = -(2.4+0.75*i);
i++;
}
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 7 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