Action script to move objects

Hi guys

Ive been playing around with flash as a substitute for powerpoint, and im looking to re-create my companies presentations and jazz em up a bit.

my presentation

The link above shows my first attempt at getting the background lens flare to move, without using actionscript. (click the arrows in the bottom right)

I need to create a system which moves the lensflare to 4 set positions, and kind of runs in series when the back / forward buttons are pressed.

Can anyone point me in the right direction?

Cheers for any response.

John

Lense flare tutorial:

Click here.

May or may not be what you’re looking for…

The buttons may be as simple as setting the _x and _y of a movie clip of a lense flare. So [COLOR=blue]on (release)[/COLOR] for each button would change the x and y properties of the movie clip. If you wanted a smoother moving, or effect, then you’d have to add more script but that’s not too difficult.

okay… thanks for the link / comments,

I can move an object with action script like this:

onClipEvent(enterFrame) {
speed = 1;
this._x += speed;

}

How do i stop this object once its reaches a certain point? Im guessing i needsomething like:

if this._x = 30
stop();

But that doesnt seem to work…

Once i get my head round this I can sort out the buttons in the presentation with a number of “if” statements, telling each circle where to go to if it is in a certain position.

Also… how do i change the “easing” using AS?

Thanks alot for the help.

John

onClipEvent (load) {
speed = 1
this._x = whatever position
}

onClipEvent(enterFrame) {
if (this._x<=30) {
this._x += speed; maybe this._x -= speed (depend on direction)
}

}

Have to go and double check… should work though…

That should move the x by +1 each time the clip enters a frame (so depends on your fps). But only does it if the x is less than or equal to 30.

About the easing thing, my personal god robert penner has written amazing easing equations. Check them on his site. They’re weird but not that hard to use.

pom :asian:

thanks alot… I think i can do it now…

Cheers for the help :smiley:

This:

onClipEvent (load) {
speed = 5
this._x = 112
this._y = 136

}

onClipEvent(enterFrame) {
if (this._x<=796.2) {
this._x += speed; }

if (this._y<=28.1) {
this._y += speed; }

}

Makes the square move across the screen and stop. How would i put this into a button, so when the button is clicked, the square begins to move then stops?

This was my attempt…

next.onRelease = function() {

==I need to put the name of the movice clip i want to move in somewhere…==

square {
speed = 5
this._x = 112
this._y = 136

}

onClipEvent(enterFrame) {
if (this._x<=796.2) {
this._x += speed; }

if (this._y<=28.1) {
this._y += speed; }

}

hmmm

you put it into the MC that is going to be moving, then have your buttons call the MC

Peace

Ryall is right. You’d put the animation in a movie clip, but I’m thinking on how to call it. OnClipEvent hadlers go in the main actions of a movie script and you can’t put them “inside” the movie clip so I don’t know how you’d use a [COLOR=blue]stop();[/COLOR] before the code if you know what I mean.

You could use a variable maybe like moveIT, eg
[COLOR=blue]
on (release) {
moveIT = true;
}[/COLOR]

then
[COLOR=blue]
onClipEvent (load) {
speed = 5
this._x = 112
this._y = 136
function resetIT() {
this._x = 112
this._y =136
}
moveIT = false;
}

}

onClipEvent(enterFrame) {
if ((this._x<=796.2) && (this._y<=28.1) && (moveIT == true)) {
this._x += speed;
this._y += speed;
}
[/COLOR]
Thats off the top of my head so bound to be wrong. Basically the button sets a variable [COLOR=blue]moveIT[/COLOR] to true. Then every frame while the x<=796.2 and y <= 28.1 and the moveIT is true, the animation will move until it gets to those x, y coordinates.

The resetIT is to reset the animation and turn moveIT to false.

Is that clear… or is there an easier way?

Actually I just thought, you could put a stop(); on the movie clip and tell the button to play(); it. It would stop once it gets to the x and y boundaries. But you’d have to reset it once it got there if you wanted the animation to occurr every time the button is pressed.

liked ur lens flare effect works quite well um if u want anything to ease u have to do this…


onClipEvent(enterFrame){
	_y += (yTarget - _y)* .97;
	_x += (xTarget - _x)*.97;
}

Where xtarget is the posistion you are moving towards…that should start off fast then gradualy slow down :slight_smile:

thanks for all the help guys… MUCH appreciated… will work on it this morning and come back to yall later :smiley: :smiley: :smiley:

okay… lets see if i have understood what the AS is doing…

//This bit:

on (release) {
moveIT = true;
}

//Goes on the button, and basically is a check variable to see whether the button has been pressed…

//this next bit goes on the movie clip that i want to make move.

onClipEvent (load) {
speed = 5
this._x = 112
this._y = 136
function resetIT() {
this._x = 112
this._y =136
}
moveIT = false;
}

//onClipEvent (load) means that all the following stuff is done when the movie is loaded up. Im a little foxed at what the function resetIT is for… But basically we are saying that at the start of the movie, moiveIT is false so it shouldnt move.

}

onClipEvent(enterFrame) {
if ((this._x<=796.2) && (this._y<=28.1) && (moveIT == true)) {
this._x += speed;
this._y += speed;
}

//This again, goes within the mc that i want to move. onclipevent(enterframe) means that… hmmmm, not sure… i have looked it up in the action script dictionary, but im still a bit foxed… but, basically, this says if the button is pressed, and the mc wanting to be moved isnt at the specific x / y co-ords then it needs to be moved at “speed”…

problem is… it doesnt seem to move… It doesnt give me a code error… so the codings fine…

i’ll upload the fla.

I also tried it the other way with the stop’s / play’s, which works, the square moves around the screen… but im not sure thats really the route I want to take because I need to be able to go backwards and forward.

xmovement.fla is the one without plays / stops
xmovementcrappy.fla has the stops / plays

Thanks again for any help… :slight_smile:

John

fla’s and swfs

welcome to the Ragew0lf lecture :stuck_out_tongue:

Hi,
this is basically the code I used to make my pointer move, there were 6 positions in total, this shows positioning for just one. This code was attached to a movie clip called “pointer” which was basically a movie which just contained the graphic of a pointer, I used actionscript to make it move around.

I stayed away from using this.value as if the code is attached attached to a singular movie clip it is unecessary, just makes things more complicated.


onClipEvent (load) { // this sets the starting position of everything
	trip = 0;   //  trip is a value alterred when a button is pressed
	rateOfChange = 7; // this is similar to your speed variable
	_alpha = 0; // starting alpha value = 0
	_x = 156;  // starting x position (top right)
	_y = -94; // starting y position (top)
	_rotation = 0; // no rotation
}
// if the button located bottom left is pressed the following happens :

onClipEvent (enterFrame) {
	if (trip == 4) { // when the button is pressed its sets the value of trip to 4. my frame rate is 30fps, 
//so 30 times a second its checking the entire code - is the value equal to 4, yes so does the following below =
		_y = 95; // changes y position to 95 which is bottom
		_rotation = 180; // want the pointer upwards so flips it
		_alpha += rateOfChange; // the first time a button is pressed I want the pointer to fade in,
// the first time the clip was loaded the value was 0, so if this was the first button pressed the pointer will gradually fade in.
		if (_alpha>93) {  // rateOfChange = 7, 100 - 7 = 93, basically if its increasing by 7 
//at some point it will have to be larger than 93, if its larger than 93, set it to 100.
			_alpha = 100; 
		}
		newx = (_x -= rateOfChange); // to keep things uncomplicated newx is a new variable determining the new _x position of the clip. 
//as -156 is the lowest value of _x that is gonna be used in the movie, it will HAVE to be _x - = rateOfchange. 
//Anyway the above code decreases the _x value at a rate of 7 each frame. 
	}
}
onClipEvent (enterFrame) { // I could have put this in the loop above but its easy to pick out and change in its own loop.
	if (newx<-155) { // at some point the _x value will be smaller that -155 
//because its decreasing at a rate of 7 each frame. when it is smaller that -155 
		_x = -156; // set the value to -156 which is the final position of the pointer until another button is pressed.
	}
}

The code for the other buttons is very similar, just dif “trip” values and x and y positions.
Your code looks pretty similar, I’m too tired to look over code right now, but if you still having trouble when I wake up I’ll take a look for you. at a glance your code seems to be very nearly correct at least, check these things :

**make sure the movie clip you are controlling has an instance name, or you won’t be able to control it.

secondly, when your buttons are pressed you need to set the value inside the movie clip itself. to do this you add the following :
**


on (release) {
    pointer.trip = 4; // (movieclipname.value = new value) 
// for you it would be movieclipname.moveIT = True
}

my code without commentary =


onClipEvent (load) {
	trip = 0;  
	rateOfChange = 7; 
	_alpha = 0; 
	_x = 156;  
	_y = -94; 
	_rotation = 0; 
}
onClipEvent (enterFrame) {
	if (trip == 4) {
		_y = 95;
		_rotation = 180;
		_alpha += rateOfChange;
		if (_alpha>93) {
			_alpha = 100;
		}
		newx = (_x -= rateOfChange);
	}
}
onClipEvent (enterFrame) {
	if (newx<-155) {
		_x = -156;
	}
}

Hope something there helps!

Wow!!! thanks rage… you are quite possibly the coolest person in the entire world :slight_smile:

the explanations help so so so much… thanks for ya time… gonna play with it today… CHEEERS!!!

RAAHHHH!!!

:slight_smile: :slight_smile: :slight_smile: :slight_smile:

*Originally posted by Hobbes *
**you are quite possibly the coolest person in the entire world :slight_smile:
**

:bandit:

okay… nearly working…

I have 2 buttons, the AS is as follows…

//button 1

on (release) {
pointer.trip = 3;

//button 2

on (release) {
pointer.trip = 4;

So on the pointer script underneath the trip == 4 AS, i need to add a similar script changing the x / y variables for tirp 3… right?

so…

onClipEvent (load) {
trip = 0;
rateOfChange = 7;
_alpha = 0;
_x = 156;
_y = -94;
_rotation = 0;
}

// the above script is only written once… and isnt repeated…

}
onClipEvent (enterFrame) {
if (trip == 4) {
_y = 95;
_rotation = 180;
_alpha += rateOfChange;
if (_alpha>93) {
_alpha = 100;
}
newx = (_x -= rateOfChange);
}
}
onClipEvent (enterFrame) {
if (newx<-155) {
_x = -156;
}
}

// this deals with trip = 4

// now i need to add a script dealing with trip = 3, so…

}
onClipEvent (enterFrame) {
if (trip == 3) {
_y = 95;
_rotation = 180;
_alpha += rateOfChange;
if (_alpha>93) {
_alpha = 100;
}
newx = (_x -= rateOfChange);
}
}
onClipEvent (enterFrame) {
if (newx<-155) {
_x = -156;
}
}

// Which bit do i need to change to move the pointer to a new pos?.. sorry if this seems like a silly question, but i have changed all the values and havent managed to get the desired effect as of yet…

tar for the help…

much appreciated!

John