Forum Moderators: open

Message Too Old, No Replies

Action Scripted movement of MClip

         

zackattack

12:19 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



I need to control movement of a movieclip with AS in the x and y axis, up, down side to side. I was building this using the time line, but I understand it can be done using AS

Anyone able to help?

ZA

Richard_N

2:54 pm on Jun 24, 2005 (gmt 0)



yes but how is it to be controlled? onClipevent, onPress what?

simply is its when the movie loads just place this in frame 1 of your main timeline...

path.to.clip_mc.onEnterFrame = function() {
clipspeed = (cliptarget-this._x)/6;
this._x += clipspeed;
};
//
var clipspeed:Number = 0;
var cliptarget:Number = 450;

path.to is the refeence to the clip to move which has an instance name of clip_mc

Place the clip where you want it to start from on the x axis and change the variable for cliptargert to the x co-ords wher you want it to end up

the /6 controls the speed it moves, the lower the number the faster it goes then brakes, and stops (in simple terms)

zackattack

5:25 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



Thank you Richard

Ok should have specified first, I have four hotspots (one for each direction) with the following code:

on(rollOver){

}
on(rollOut){

}
How would I apply this to what you have just written?

ZA

Richard_N

8:11 pm on Jun 24, 2005 (gmt 0)



wrap it in a

pathto.buttonname_btn.onRollover = function(){
//previous example goes here
}

zackattack

9:01 pm on Jun 25, 2005 (gmt 0)

10+ Year Member



Richard Thanks I am trying this out and will get back to you if I get stuck, if thats ok..

thanks again

ZA

zackattack

4:47 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



Hi Richard

sorry being a a bit thick here, I have created my four buttons... an example of one function attached:

this.upButton.onRollover = function(){
clipspeed = (cliptarget-this._x)/6;
this._x += clipspeed;
};
//
var clipspeed:Number = 0;
var cliptarget:Number = 450;

I need to target the movie clip that this is controlling, I cant quite figure out where to put it, have tried different ways.. my movie clip instance is called clipWindow

I also need to stop the movement on rollout, is it something like

this.upButton.onRollout = function(){
clipspeed = (cliptarget-this._x)/0;
this._x += clipspeed;
};

where 0 stops it ..?

One of the problems is I dont quite understand what I am asking flash to do, if Its possible for brief explanation it would be very very helpful

ZA

Richard_N

6:17 pm on Jun 27, 2005 (gmt 0)



what your doing is placing this script on the maintimeline and referencing the clip and button from there. Its a more efficient and tidy way of programming retaining all the code in one place

OK first you need to set up a callback function for the button ( //are comments )

//button function
buttonname_btn.onRollover = function(){

//now set up a call back for inertia function of //clipWindow
clipWindow.onEnterFrame = function() {
clipspeed = (arollovertarget-this._x)/6;
this._x += clipspeed;
};
}

//variables second is where the clip ends uo on x axis
var clipspeed:Number = 0;
var arollovertarget:Number = 450;

and thats it, just repeat the process for rollOut, define all functions first, then put the variables at the end of the script. so for rollover you will need to define a new target such as

var brollovertarget:Number = 200;

//in english
//on mouse over
// clip (a) rollover target is _x=450
//and on mouse out
//clip (b) rollover target is _x=200

zackattack

1:51 pm on Jun 29, 2005 (gmt 0)

10+ Year Member



Richard, I have spent ages trying to figure this out and still am stuck

I have added code as below, tried to make a right movement but cant work out what is changing what, so there is little chance I can work out how to make up and down and the rollout stop the action either...

//button function
this.leftButton.onRollover = function(){

//now set up a call back for inertia function of //clipWindow
clipWindow.onEnterFrame = function() {
clipspeed = (arollovertarget-this._x)/6;
this._x += clipspeed;
};
}

//button function
this.rightButton.onRollover = function(){

//now set up a call back for inertia function of //clipWindow
clipWindow.onEnterFrame = function() {
clipspeed = (crollovertarget-this._x)/6; //tried putting y in here to make up and down too
this._x += clipspeed;
};
}
//variables second is where the clip ends uo on x axis
var clipspeed:Number = 0;
var arollovertarget:Number = 650;
var crollovertarget:Number = -650; //tried putting minus in here

I have books on this stuff but still am completely confused. Can you give me any more help and explanation?

ZA

Richard_N

4:48 pm on Jun 29, 2005 (gmt 0)



Sorry done my best to explain it, but I suggest perhaps you get a book on actionscript basics, it may make it clearer as you are having to grasp a few concepts in one here

zackattack

10:38 pm on Jun 29, 2005 (gmt 0)

10+ Year Member



Thanks anyway for your time, guess I will have to work it out another way

ZA