Groups | Blog | Home
all groups > flash actionscript > june 2004 >

flash actionscript : How is this scroller done


dhx10000
6/3/2004 10:59:42 PM
Hi,

Go here:

http://www.tolleson.com

then click on 'Applied Materials',
then click on the numbers to view the images.

It presents the images as if they are a 'roll of film'. I understand how to
set it up in terms of using one giant collage of images and using a mask to
display each image, but I don't understand the actionscript part that causes
the images to jump to whatever image you want. Any hints/tutorials, please? I'm
using Flash MX (6.0)

Thanks,

SR
gorlins
6/3/2004 11:13:50 PM
once you have the collage set up in a mask, all you need to do is animate its
position. give it a name like collage_mc, and give it the attached code.
When you click the image index, call _root.collage_mc.setTarget(x, y); where x
and y are the positions where the appropriate image is viewable. Note that
this uses a linear function to slowly decellerate the movie clip to the new
position -- it moves it a certain percentage of the remaining distance to the
final target each frame. You can give it any function you want to control how
it looks, for instance, on my website (link below) i change the velocity of the
object depending on the distance, which gives a nice bouncing effect

onClipEvent(load)
{
myRate = 0.2; // A variable controlling how fast the image scolls, play with
it
targetX = _x;
targetY = _y;
setTarget = function (newTX, newTY)
{
targetX = newTX;
targetY = newTY;
};
moveMe = function ()
{
_x += myRate * (targetX - _x);
_y += myRate * (targetY - _y);
};
}
onClipEvent(enterFrame)
{
moveMe();
}
dhx10000
6/4/2004 5:25:07 PM
Hi Gorlins,

Thanks for the tip, but I keep receiving the following errors:

Symbol=collage_mc, Layer=text, Frame=1: Line 1: Clip events are permitted only
for movie clip instances
onClipEvent(load)

Symbol=collage_mc, Layer=text, Frame=1: Line 19: Clip events are permitted
only for movie clip instances
onClipEvent(enterFrame)

Where exactly do I add the onClicpEvent code?


dhx10000
6/4/2004 5:28:22 PM
Here is my .fla file if it helps...

gorlins
6/4/2004 9:07:31 PM
Here are your three problems, fix them and it will work:

1) You put the code into the first frame inside of the movie clip instead of
giving the instance a copy of it. Here's the difference - where you put it, it
is a frame action and gets called each time that frame is entered. onClipEvents
can only be assigned to instances, which are copies of library items on the
stage or in other movie clips. You can write equivalent code in either place,
but not with an onClipEvent handler. So: cut the code from the first frame,
select the instance on your timeline, and paste it into the actions window for
the instance.

2) You didn't specify an instance name. Your button calls
_root.collage_mc.setTarget(); which is the library name of your clip but not
the instance name. You set the instance name in the text field right below the
drop down list for movie clip, graphic, or button in your property inspector.
This may seem counter intuitive at first, but it allows you to have more than
one instance of the same library object at any given time and treat them
differently in actionscript. Actionscript only referrs to the instance name,
so change that to collage_mc.

3) The x,y coordinates you use in the setTarget(x,y) commands were off. The
code in the setTarget function refers to this._x and this._y (this is the
default object for any property if no object is specified, ie _parent._x or
myObject._x), where this is the instance of your clip on the stage. Therefore,
the x,y coordinates have to be relative to the stage. The way your clips are
set up now, the first button should read something like setTarget(200, 220).
Note, however, these numbers will be different if you put the instance into
another movie clip, because then you would need the x, y coordinates of the
movie clip it's in.

Fix those three and everything works fine
AddThis Social Bookmark Button