PDA

View Full Version : angle....


sandman9
01-23-2003, 04:57 PM
in this movie:

http://www.netpub.cstudies.ubc.ca/sull/latest.swf

I want to place that swizzle stick that's on the left on an angle ........ so I need that olive tracking up and down on an angle as well

the script on the olive is as follows:

onClipEvent (load) {
Ypos = -128;
}
onClipEvent (enterFrame) {
Ya = _root.bottone1._y;
Ydiff = Ypos-Ya;
Ymove = Ydiff/4;
_root.bottone1._y = Ya+Ymove+43;
}


And the script on the buttons is as follows:

on (rollOver) {
_root.bottone1.Ypos = -44;
}

That -44 is just the location of one of the particular buttons so that value will change according to which ever button

Sandman9

sandman9
01-24-2003, 06:10 AM
anyone know how to do this?

Sandman9

dr.swank
01-24-2003, 06:42 AM
object._angle=90

would be your code for that.

sandman9
01-24-2003, 06:43 AM
can you clarify please ....... where in the code above would you put it?

Sandman9

dr.swank
01-24-2003, 07:36 AM
I have to runn to an appointment. I will get back to you later on this. just a hint:

angle is a property you can set. you can put it on root, or on a button to change the angle dynamically, or in a loop to animate it based on something happening... like I said, its an adjustable property. read the reference section in mx for an explanation.

till later then, cheers, dr.s

sandman9
01-24-2003, 05:20 PM
I try'd a couple things but still no luck ....... also there's gotta be other coding that goes with that script as well uh?

If you could get back to me on weather that script goes on the olive, button, etc that would be awsome

Sandman9

dr.swank
01-24-2003, 08:32 PM
oh SHlT! :eek: , I am sorry dude, I must have had a brain short cuircut. its not _angle, its _rotation.

try this on a button:

on(press){
olive_mc._rotation=78
}


Again I am really sorry abot that!

dr.s

sandman9
01-24-2003, 09:46 PM
Thx for the reply but I don't need the olive to rotate ..... i need it to slide up and down on an angle ....

Sandman9

dr.swank
01-25-2003, 07:55 AM
OHHHHHhhhhh... hmmm,

that much easier.

it requires the setting of the _x and _y position. if you toothpick goes from 100:100 to 200:500 (x:y) then you just need to do the math and then put that slope in your code. if you post your fla i can build it in there for you and write some notes to explain it there as well.

cheers, dr.s

sandman9
01-25-2003, 05:50 PM
i try'd that but had no luck ....... Also I did it a bit different, see coding above

Thx
Sandman9

cheez
01-25-2003, 06:03 PM
Show off! ;)

That's right Swanky-D, I'm watching you! You better watch out...I might start asking you to write some of my code!

Cheers!:)
-Cheez

if you post your fla i can build it in there for you and write some notes to explain it there as well.

cheers, dr.s

Ricod
01-25-2003, 09:07 PM
And to help the forum : Why don't you post what you did right here ;) !

dr.swank
01-25-2003, 09:43 PM
gents, I would be happy to write a little function thingie to do this. But I am going to sit and have a drink with my wife. :D I will post a simple thing here tomorrow. stay posted... and cheez just so you know, I have eyes in the back of my head :cool: hey!, I saw that... haha

till the morning light. dr.s

dr.swank
01-25-2003, 11:13 PM
alright y'all, here is the code:


// this is the toggle to start or stop the animation
var running = 0;
var goalX
var goalY
//this is the running setter function, I do this because
//if I need to change this code, I only need to change it here/
setRunning = function () {
if (!running) {
running = 1;
} else {
running = 0;
}
};
// this is the code that moves the mc, not the running requirement.
this.onEnterFrame = function() {
if (running) {
trace("running")
// moves node to target
olive_mc._x -= ((olive_mc._x-(goalX-olive_mc._x))*.05);//if you rase the value here it will move faster
olive_mc._y -= ((olive_mc._y-(goalY-olive_mc._y))*.05);
}
};
// this is the button code. I like to use event handlers because thay are a but easier to deal with
bt1_mc.onPress = function() {
setRunning()// this sets the rinning variable
if (olive_mc._y>80) {// this is just a conditional to make the olive move back and forth
goalX = 40;
goalY = 40;
} else {
goalX = 200;
goalY = 400;
}
};


and the attached fla.

happy coding, i'll be back tomorrow for answers to any questions.

:) dr.s

sandman9
01-26-2003, 03:10 AM
Thx for the responses guys!!!

Dr. Swank ..... I think the concept you have in that file ^^^^ is right but it's differ from my example here:

http://www.inplode.com/sandeep/latest.swf

I was needing that ball to track up and down on an angle from button to button and not move to a location on the click of just one button .... so all that high end scripting may not even have been neccesarry :p ...... however, very impressive :D

Sandman9

Ricod
01-26-2003, 04:48 AM
impressively fast !

dr.swank, how's sleeping on the couch ? Blowing of your wife like that useally isn't the best way to spend the weekend :D !

sandman9
01-26-2003, 04:55 AM
^^^LOL ...... that mean I'm the culpret here :D

Sandman9

dr.swank
01-26-2003, 08:26 AM
sandman9,

thanx for the compliment. :)... to use the code in your example you can put the goalX and goalY on the rollover of your button::

on(rollOver){
_root.goalX=100
_root.goalY= 600
}


its thae same as what youu have now exept you are adding the x position as well as the y position to you defining variables. It is not that complex, its like telling the olive to , well, move in 2 directions

Give it a shot. cheers, Dr.S

sandman9
01-27-2003, 05:53 AM
Script on button:

on (rollOver) {
_root.bottone1.Ypos = -124;
}


Script on Olive:

onClipEvent (load) {
Ypos = -128;
}
onClipEvent (enterFrame) {
Ya = _root.bottone1._y;
Ydiff = Ypos-Ya;
Ymove = Ydiff/4;
_root.bottone1._y = Ya+Ymove+43;
}


Bear with me for I'm a begginer but my guess would be that on the button I would add _root.bottone1.Xpos = (whatever location);

So this leads me to believe that I would have to clarify a X position on my olive aswell so underneath Ypos = -128; I added Xpos = (some location); ......... this did not work. Can anyone tell me what I'm doing wrong?

Thx
Sandman9

sandman9
01-27-2003, 05:59 AM
on the olive I try'd this:

onClipEvent (load) {
Ypos = -128;
Xpos = -150;
}
onClipEvent (enterFrame) {
Ya = _root.bottone1._y;
Ydiff = Ypos-Ya;
Ymove = Ydiff/4;
_root.bottone1._x = Xa+Xmove+43;
Xa = _root.bottone1._x;
Xdiff = Xpos-Xa;
Xmove = Xdiff/4;
_root.bottone1._x = Xa+Xmove+43;
}


Then on the button this:

on (rollOver) {
_root.bottone1.Ypos = -124;
_root.bottone1.Xpos = -150;
}


But what this did was move the button horizontally and ignored the Y position

Sandman9

dr.swank
01-27-2003, 06:37 AM
hey sandman9,

lets take a close look at what is actually doing what in my code:


// this is the toggle to start or stop the animation
var running = 0;
var goalX
var goalY

this part sets up three variables. the running variable is just an "on/off" switch that determines if the movement code should be moving something.
the goal variable are nothing except the place the movement code is going to move the olive to.


//this is the running setter function, I do this because
//if I need to change this code, I only need to change it here/
setRunning = function () {
if (!running) {
running = 1;
} else {
running = 0;
}
};

this is just a fancy looking way of making the code a little cleaner. this function turns the running variable on or off depending on weather it is , well on, or off.


// this is the code that moves the mc,
this.onEnterFrame = function() {
if (running) {
trace("running")
// moves node to target
olive_mc._x -= ((olive_mc._x-(goalX-olive_mc._x))*.05);//if you rase the value here it will move faster
olive_mc._y -= ((olive_mc._y-(goalY-olive_mc._y))*.05);
}
};

this is what actually does the movement. "this." refers to the swf, and "onEnterFrame" tell the swf to do this block of code everytime the frame is entered meaning at 12fps it executes 12 times per second. the equation uses the minus equals operator which does nothing other than subtract the right side from the left side of the equation and then make the variable on the left side equal to the result . that way it incrementally reduces the value. if you look at the equation you will see why it works.


// this is the button code. I like to use event handlers because thay are a but easier to deal with
bt1_mc.onPress = function() {
setRunning()// this sets the rinning variable
if (olive_mc._y>80) {// this is just a conditional to make the olive move back and forth
goalX = 40;
goalY = 40;
} else {
goalX = 200;
goalY = 400;
}
};



this button code only sets the goal variable and the running variable. meaning that it will turn on/off the movement code and tell the movement code where to move the olive to. now to my recommendation of the new code on the button:


on(rollOver){
_root.running=1
_root.goalX=100
_root.goalY= 600
}



this is the flash 5 syntax for button events handler. You can use it if you want. I will not go into the MX events handler here as it is well described in the tut section. If you put this code with different goalX and goalY on it on your buttons you will see how the code makes your olive move. I did forget the running var in the code. sorry. give it a try now and see how it works.

I do not want to dismiss your code, but, looking at the length of it, I assume that this method is cleaner.

I hope this helps. Cheers dr.s