Forum Topic: someone please check this code?

(137 views • 8 replies)

This topic is 1 page long.

<< < > >>
None

korded

Reply To Post Reply & Quote

Posted at: 4/28/08 05:57 PM

korded EVIL LEVEL 06

Sign-Up: 02/06/00

Posts: 1,094

Hey, trying to create a zipper effect using this guy's tutorial.

Mind you of course, that was done in SwishMax which I've never used before, but the language seems to work basically the same.. or is it the same?

Anyway, I'm having a little trouble getting it to work, I've never gotten into mathematical functions before. All movieclips in my swf are on the main timeline, and all of the code is on the first frame of the main timeline. I have a zipper tab movieclip named "tab", and zipper teeth mc's; left ones are named l1 through l46, right teeth are named r1 through r46.. just as in the mentioned tutorial.

Here's my code:

//declared variables
var pressed:Boolean = false;
var distance:Number = 0;
var curve:Number;

//drag function
tab.onPress = function() {
pressed = true;
tab.startDrag(false, tab._x, 0, tab._x, 570);
}
tab.onRelease = function() {
pressed = false;
tab.stopDrag();
}

//teeth separation function
onEnterFrame = function() {
distance = tab._y;
for (i=1; i<=46; i++) {
curve = math.exp(i/3*0.9+.5);
["l"+i]_x = -3-(distance/curve);
["r"+i]_x = 3+(distance/curve);
}
}

Resulting swf has a functioning zipper tab which drags as expected, but teeth remain in place. The "curve" variable remains undefined. Any ideas?


None

Temp967

Reply To Post Reply & Quote

Posted at: 4/28/08 06:19 PM

Temp967 LIGHT LEVEL 04

Sign-Up: 01/01/07

Posts: 85

I'm thinking the M in math.exp( should be uppercase. Math.exp(


None

korded

Reply To Post Reply & Quote

Posted at: 4/28/08 06:34 PM

korded EVIL LEVEL 06

Sign-Up: 02/06/00

Posts: 1,094

At 4/28/08 06:19 PM, Temp967 wrote: I'm thinking the M in math.exp( should be uppercase. Math.exp(

Nice find, the teeth still aren't moving though. However, my "curve" variable is at least evaluating now to a number.


None

Temp967

Reply To Post Reply & Quote

Posted at: 4/28/08 06:40 PM

Temp967 LIGHT LEVEL 04

Sign-Up: 01/01/07

Posts: 85

~I'm no good at AS3.0, so forgive me if I'm wrong. But just in case, try separating the "_x" from ["l"+i]
by using a period. Like so, [["l"+i]._x and also for the one beneath it. I'm not sure if it'll work, but it's worth a try :).


None

korded

Reply To Post Reply & Quote

Posted at: 4/28/08 07:12 PM

korded EVIL LEVEL 06

Sign-Up: 02/06/00

Posts: 1,094

Hm, still no good.. the dots were originally there actually, I had to take them out to avoid errors. I think in cases like these where expressions are part of the target path, they aren't used. I'm wondering if it would be best to stick the .fla up somewhere.


None

korded

Reply To Post Reply & Quote

Posted at: 4/28/08 07:49 PM

korded EVIL LEVEL 06

Sign-Up: 02/06/00

Posts: 1,094

Alright, getting somewhere, at least I hope so,

I was checking the structure of the expressions used to reference the teeth, and found you were indeed right; I had to add a period before the _x property. However, I also had to add _root to the beginning of each reference. The movie is now communicating with the zipper tooth movieclips, though when I tested the movie it automatically sets the whole zipper to the far left side of the screen - good news though is that the zipper works! I have to figure out why it sets it to the left though, and I'll have to mess with the math.exp function to get the proper curve, but this is definitely a start.


None

korded

Reply To Post Reply & Quote

Posted at: 4/29/08 10:32 AM

korded EVIL LEVEL 06

Sign-Up: 02/06/00

Posts: 1,094

Got it working after a lot of work - I don't think anyone would of had much luck with this unless they had the .fla to work with. Just thought I'd post the final code for anyone who's interested, I'll show the result once it's complete.

//teeth separation function
onEnterFrame = function() {
distance = tab._y; //distance of tab from top of page
for (i=1; i<=46; i++) {
curve = Math.exp(i/7*0.6+0.5);
angle = Math.exp(i/7*0.6+1.5);
_root.zipper["l"+i]._x = -3-(distance/curve);
_root.zipper["r"+i]._x = 3+(distance/curve);
_root.zipper["l"+i]._rotation = -3-(distance/angle);
_root.zipper["r"+i]._rotation = 3+(distance/angle);
}
}


None

korded

Reply To Post Reply & Quote

Posted at: 4/30/08 02:37 AM

korded EVIL LEVEL 06

Sign-Up: 02/06/00

Posts: 1,094

Done, finally. Result is here - http://dustinshadoe.com


None

Hoeloe

Reply To Post Reply & Quote

Posted at: 4/30/08 03:03 AM

Hoeloe LIGHT LEVEL 29

Sign-Up: 04/29/04

Posts: 5,032

Very nice indeed! I congratulate you.

Sex!
------------------------------
Super Nuke Bros. Melee, the web's no. 1 awaited Super Smash Tribute Game!

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 07:57 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!