Groups | Blog | Home
all groups > flash actionscript > march 2007 >

flash actionscript : MovieClip Scroller



Martyn_C
3/22/2007 8:05:05 PM
Hi,

I'm trying to do something really basic, but, I think I am complicated the
thing. I'm trying to do a slidebar that when you drag it, a MovieClip begins to
move. When your are the start of the scroll bar, the movie clip is at the start
and when your at the end of it, the movie clip is at his maximum (._x). You can
see what I did yesterday http://www.martinc.biz/myissue/ and at the same time,
you will see the problem I have with it. Can someone help me? I try to do it as
simple as possible. You can download my .FLA
http://www.martinc.biz/myissue/glissiere2004.fla And I would like to know what
I did wrong (even if it's everything...)

Thanks for your help!
eric76
3/24/2007 4:40:41 PM
Yes I think u are complicating things. However I have a hard time seeing
exactly where and why, because I dunno french (it is french isnt it?), so it's
hard for me to understand the code. However, add this simple code to your
glissere actionscript:
onEnterFrame = function() {
_root.grosClipCarresRouges._x = (100 - poignee._x) * 2.2;
};
It should get u going...
The constants 100 and 2.2 I got from trial and error. In general it's better
to not to hard code such values but take the different dimensions as arguments
to a function which then calculates them.
Martyn_C
3/28/2007 8:48:45 PM
I finally succeed to do what I was trying to do! You can see it at this URL:
http://www.martinc.biz/solveissue/

What I was trying to do is to this without that code:

onClipEvent (enterFrame) {
this._x = _root.glissiere.poignee._x * 2.5;
}

Because, in many books I read, some Flash developers says that it's not a good
way to put Actions directly on instances (and it's very amateurish). Can
someone tell me how to do the same thing WITHOUT put any code on instance?

Thanks a lot for your help !
eric76
4/5/2007 4:30:55 PM
Writing code directly on instances is error prone. What u do is write a
function for the movieclip that contains the boxes, e.g. moveBoxes(x), and then
u can have an onEnterFrame in _root, that propagates any scroll movements to
the boxes, like:
boxes.moveBoxes(someFormulaOf(scrollbar.x));
(Variablenames in english)
AddThis Social Bookmark Button