Slide menu

well i was reading this tutorial…
http://www.kirupa.com/developer/flash5/slidingmenu.htm

And i dont’ really understand this line…i know its a tutorial but i can’t seem to find where it explains this line…
[AS]
onClipEvent (load) {
_root.xnew = _root.mask2._x + (4-1)*100/2 ;
}
[/AS]

All it says is it sets a new position for the main slide thing, but why 4-1? and then multiply by 100 divided by 2?

And another quesiton, is why using prototypes? I read the thing about it in the AS tricks, but is there a general answer to it, so i know when to apply it in the future…thx

that is a line of code that is executed once: when the instance is…well…instanciated or loaded (hence load). what this seems to be doing is setting a variable _root.xnew

it’s setting it to the value of the x location of _root.mask2 (in the form _root.mask2._x) and adding the value (4-1)*100/2;

[edit]:

it’s not necessarily setting a position as the code is only calling for the location. and it also eludes me why that person put a mathematical constant in the form of an equation when he could’ve just solved it outside AS.

and as for prototypes, they are exactly like functions only, you can attach them to certain objects. the advantage of this is that with each object instance (duplicate, if you will), you can call that function and it will behave exactly like it would with any other object. the catch and advantage of prototypes though is the function can only be called by that object and nothing else.

yea i get that part, but is there any reason for choosing those particular numbers? like 4, 1, 100, 2?!

the writer of that code must’ve had some special reason and it’s a shame he didn’t document it.

hmm, well i think ive figured wat the 100 and 2 are, which are just postitions…but why not just 50!? anyways why si it an advantage that it can only be called by an object?! I still don’t really see why it is better :-\

well, prototype functions have the capability of manipulating variables that are fixated, or unique to that certain object (are you familiar with classes in c++). calling the function from just anywhere (aside from impossible with prototypes) can have adverse effects. for example with a prototype like so:


MovieClip.prototype.moveLeft = function () {
this._x--;
};

you can’t have an array object move left like a movieclip can. it simply doesn’t have the “this._x” variable, or property. on the flip side you can have certain functions that only deal with arrays and not movieclips.

alrite i get that part thx…

but this part…
[AS]
MovieClip.prototype.move2 = function () {
dest = _root.xnew ;
pos = this._x ;
vel = vel*0.7 + (dest-pos)/7 ;
this._x += vel ;
}
[/AS]

i understand that, but when it says this._x, what exactly is it referring to? the mask? or the moving clip?

it’s referring to the _x property of whatever object that calls this function. i can’t say any further since this is only the prototype. look for the actual movieclip that calls this function, like “ball.move2();” or something. in this example, the _x would be referring to “ball”'s _x.

well the only thing that is reffering to it is the line…
[AS]
onClipEvent (enterFrame) {
move2 () ;
}
[/AS]

so what would that be? the frame?

no whatever movieclip this code is in, since you can only call “onClipEvent” in a movieclip.

ah yes…i see. Alrite i get the thing now, thx a lot for your help :slight_smile:

yep, that’s what i’m here for :slight_smile:

*Originally posted by blah-de-blah *
**hmm, well i think ive figured wat the 100 and 2 are, which are just postitions…but why not just 50!? anyways why si it an advantage that it can only be called by an object?! I still don’t really see why it is better :-\ **
Yeah, that code isn’t really clear, sorry about that. It’s just that I was afraid that if I just put 150 instead of (4-1)*100/2, people wouldn’t understand where this number came from :slight_smile:

4-1 refers to the number of the cell (it’s the fourth, but it starts from 0 so it is the 4-1 = 3rd)
100 is the width of the cell
/2 because the registration point is in the middle.

Anyway, I definitely need to rewrite that tute, it’s seriously outdated and badly scripted :frowning:

Ilyas…:bad:

Yes? :sure:

…oh nothing :sigh:

:bad: