FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Movement rotation action scrip





Dark-Tech
here goes i want to get a button to rotate with a change in _X so like a function

if _X changes the image will rotate in an undetermined functional way

like

button2._rotation = _x; is similar to what i want but id need it in the entire function including when and where in the code it should be
Sappho
Hmm i dont fully understand what r u trying to do. When is this button going to rotate?

When u want to rotate button on click just put it within the [on (release)] clause. Function is easy too, just define it as
function myrotation(x : Number):Void
{
button2._rotation = x;
}

of course if u meant by _x the actual relative x position of the button u should refer to it as button2._x too. And dont forget that functions are timeline dependant too, unless u use the magic _global again like:

_global.myrotation = function (x : Number):Void
{
button2._rotation = x;
}

But its not clear from ur post what u r after. :/
Dark-Tech
well for timesake this is what i want i hope this is more clear

i have a button it does anumber of things asfar as changing what it looks like through a moviclip inside the button.

i have it set so that when i (press) wit the mouse it begis a drag; and when i (release) with the mouse the drag ends;

i want it so that its rotation is always = _x the relative position of the button on the x axis if i move it right it rotates clockwise if i move it left it rotates counter clockwise
Sappho
Ok encapsulate ur button to a movieclip.

In first frame of the movieclip timeline define an onEnterFrame event:

this.onEnterFrame = function():Void
{
button._rotation = button._x;
}

Dunno if cw and ccw is correct but all u have to fix it if its the other way is using -button._x

I know using onEnterFrames is kind of nasty but it seems as the most straightforward and easiest solution, instead of hooking the mouse. I recommend u to use movie clip as encapsulator, but u can make this script work even in current _parent of the button instance.

Also there is a space for optimalization like:

this.onEnterFrame = function():Void
{
if (button._x != oldx) {
button._rotation = button._x;
oldx = button._x;
}
}

Where its going to update only when the button moves.
Dark-Tech
im now 90% sure we are using different versions of flash im using MX i think 2004

but from what you said i was able to get it to do that on the other hand a new problem arrised

code on button



on (release) {
stopDrag();
movieclip1.gotoAndPlay(_global.y);
}
on (press) {
startDrag("button");
movieclip1.gotoAndPlay(_global.x);

}



unfortunately now the
movieclip1.gotoAndPlay(_global.x);
&
movieclip1.gotoAndPlay(_global.y);

dont work

i tried reposition ing it

in the main scene where( it was)
in the button encapsulating clip,
in the button
in the moviclip the button encapsulates
- its a really complex object now i could prolly sipmplify it but there reallly is no need

- so why doesnt it work anymore?
Sappho
Yes we are using different versions of Flash since i am working with the last Flash 8 but it has no bearing onto ActionScript code since both MX 2004 and Flash 8 uses ActionScript 2 as far as i know.

Oh i see that u dont need to refer to the button instance inside the events, which is strange and maybe there is the difference between Flash 8 and MX. I would need to write it like this

Code:
on (release) {
button.stopDrag();
button.movieclip1.gotoAndPlay(_global.y);
}


since Flash 8 is working with parent's timeline inside those object events. :/ Really strange.

But where i see the problem here is that u cant refer to an instance within button. So even if u have movieclip instance inside button named "movieclip1" u cant access it with that name. :/

Try putting trace(this); at the first frame of the movieclip inside the button and u will see. It should be something like this:

Code:
_level0.button.movieclip1


but it will prolly be this:

Code:
_level0.button.instance1


Dunno if its a bug, u can go around this using movieclip instead of button and just assign onRelease event function to that movieclip.

Lets say button is a movie clip and at the first frame assign an event function like this:

Code:
this.onRelease = function():Void
{
stopDrag();
movieclip1.gotoAndPlay(_global.y);
}


And it will work, as u can see inside events defined this way u r working with a timeline of an object returning the event not with the parent timeline as above. So it is the same as ur code within event handlers. Smile
Dark-Tech
ok i see what your saying and i tried that and it worked somewhat but created another problem so confusing and complex i just dont want to talk about it. instead i decided this would just be easier


i removed movieclip1 from the main scene and removed all the actionscript from it

i created another movie clip only 1 frame with nothing in it and put it outside the visible area and put inside of it


onClipEvent (enterFrame) {

_level0.grip1._rotation = _level0.grip1._x;
}


which allows the button to rotate when i move it etc.

now my provlem is i have


on (release) {
stopDrag();
movieclip1.gotoAndPlay(_global.y);
}
on (press) {
startDrag("button");
movieclip1.gotoAndPlay(_global.x);

}



movieclip1 is now inside the button so they both rotate at the sametime and ar together while rotating

though this seems similar to one of the previous posts im not sure

what to put in the button code on the lines
movieclip1.gotoAndPlay(_global.x);
movieclip1.gotoAndPlay(_global.y);

to get them to effect the movieclip inside of the button
Sappho
As i said u cant access movieclip inside a button with the instance name defined, dunno if its a bug or its intended. U can try trace(this); within the movieclip1 timeline to see the absolute way to the instance which can be used to access it.
Dark-Tech
well that solved one problem now im a whole 1/5th of the way done lol
Related topics
FOR WAR OR NOT
Looking for a Good Action Game!
America's Army
Will Jesus Return ? WHEN / HOW ...
Action Replay vs GameShark (PS2)
xmlhttprequest
Is my web will be delete, if no action for a long time ?
Justification for War in Iraq
Not Voting is Reasonable for People Who Want Freedom
Water found on Saturn's moon
How to Save Mother Earth?
action movies for CG animation
Direct Action To Stop The War Reemerges
how to center swf title to a flash website does anyone know?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.