GlowAnims
Would you like to react to this message? Create an account in a few clicks or log in to continue.

GlowAnims

GlowAnims
 
HomePortalLatest imagesSearchRegisterLog in

 

 AS for beginners

Go down 
3 posters
AuthorMessage
Reaven
Admin
Admin
avatar


Posts : 676
Experience : 10001287
Join date : 2008-12-17
Age : 30
Location : im your neighbor!!!.....naah, im German.
Country : Germany

AS for beginners Empty
PostSubject: AS for beginners   AS for beginners I_icon_minitimeWed May 27, 2009 2:01 pm

so......i decided to show you some easy AS2 scripts....

1. Button

Its one of the easy scripts:

Code:

on(release){                
   gotoAndPlay("Scene 1",1); 
                }

when you press the button it goes to the scene which is named "Scene 1" and there to frame one


2. getURL (in this example its a button script)

Code:

on(release){                
   getURL("www.Glowanims.us.tf",_blank; 
                }

when you click the button it opens the URL in a new (_blank) window.
instead of _blank you might want to use _self(opens in the same window)




3.(INTERMEDIATE) simply walking script for games.




the first thing you need is creating a MC, its instanceName is hero.(thats the person you will walk with)
than you need to create an other MC which instanceName is ground.(its the ground =P)

the second thing you need is the variable for the speed....select your char(have to be a MC!) aand type the following:

Code:

onClipEvent (load) {
var speed:Number = 3;
}

var stands for variable, speed is the name of the var and the :Number = 3 tag defined the speed.

the second thing you need is a variable who says that the char touchs the ground.....and ofcorse a gravity var a scale var(to lazy to explain this):
Code:

var touchingGround:Boolean = false;
var grav:Number = 0;
var scale:Number = _xscale;

put this script in the variable section:

Code:

onClipEvent (load) {
var speed:Number = 3;
var grav:Number = 0;
var touchingGround:Boolean = false;
var scale:Number = _xscale;
}

now, this is a bit difficult:

(i won't explain all only the important things)


Code:

onClipEvent (enterFrame) {         
if (!touchingGround) {                         
grav++;                                           
this._y  = grav;                                 
} else {                                           
grav = 0;                                         
}
if (_root.ground.hitTest(_x, _y, true)) {
touchingGround = true;                     
} else {                                             
touchingGround = false;                     
}


//if the char touchs the ground
//the gravity goes up otherwise the char would fly(grav++)
//this stands for the char MC, _y is the axis , = grav means that the grav is now in use

//if the char doesn't touch the ground(else)
// gravity is 0, he jumps(grav = 0)
//if the Char hits the ground
//the script knows that he touchs the ground cause its true(touchingGround =true)
//if he doesn't touchs the ground
//its false, he jumps


now you have setted up the ground and the gravity.......whats missing?...right, the walking script for the char.

Code:

if (Key.isDown(Key.LEFT)) {
_x -= speed;
this.gotoAndStop(2);
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT)) {
_x  = speed;
this.gotoAndStop(2);
_xscale =  scale;
}

im to lazy to explain this....its just a script that let you walk on the x axis.
this.gotoAndStop(2) just says that when you press "right" it goes to the current MC(our hero) and there to the second frame....ofcorse you can change that.


heres the whole script:

Code:

onClipEvent (load) {
var speed:Number = 3;
var grav:Number = 0;
var touchingGround:Boolean = false;
var scale:Number = _xscale;
}

onClipEvent (enterFrame) {     
if (!touchingGround) {                     
grav++;                                       
this._y  = grav;                             
} else {                                       
grav = 0;                                     
}
}
onClipEvent (enterFrame){
if (_root.ground.hitTest(_x, _y, true)) {
touchingGround = true;                 
} else {                                         
touchingGround = false;                 
}

if (Key.isDown(Key.LEFT)) {
_x -= speed;
this.gotoAndStop(2);
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT)) {
_x  = speed;
this.gotoAndStop(2);
_xscale =  scale;
}
}

example for the script:
http://www.truploader.com/view/043335

contex menu:

Res requested a context menu(rightclick menu) script:

first we need to hide the default items:
Code:
var myMenu_cm:ContextMenu = new ContextMenu();
myMenu_cm.hideBuiltInItems();
_root.menu = myMenu_cm;

"var myMenu_cm:ContexMenu = new ContexMenu();" creates a variable that allows you to hide the menu.
"myMenu_cm.hideBuiltInItems();" selfexplaining....
"_root.menu = myMenu_cm;" makes the custom menu visible

so, thats the "hard" part.
you see, its very easy.

now we create some items for the menu.

Code:
var newItem1_cmi = new ContextMenuItem ("Low Quality", low_quality);
function low_quality (){
_quality = "LOW";
}

in this example it'll set the quality to low.
"var newItem1_cmi = new ContextMenuItem ("Low Quality", low_quality);"
nothing to say here, it sets the variable for the new item and the name of it, where "Low Quality" is the name that shows up in the menu.


"function low_quality (){" adds a function to it

"_quality = "LOW";"
you could add anything you want here...something about, gotoAndPlay(Scene 1,1); or so.
I'll use the _qualty thing.

"}" -.-


now you created the item but it doesn't show up in the menu.
to do this we add a simply code UNDER the variable section:

Code:
myMenu_cm.customItems.push(newItem1_cmi);

it says that "newItem1_cm"i shows now up.

THATS IT!
you can add as many items you want, just add a new item to it (newItem2_cm) and add the code above to it.



so, you may want to know how to add a separator between two items.
this is also verx simply:

newItem2_cmi.separatorBefore = true;

this adds a seperator BEFORE newItem2_cmi.......easy right?

you made you own context menu :3


I'll update this soon with some more scripts

btw sorry for bad grammar :3


Last edited by Reaven on Wed Aug 19, 2009 1:19 pm; edited 10 times in total
Back to top Go down
http://glowanims.ohost.de
Res
Admin
Admin
Res


Posts : 1616
Experience : 10002274
Join date : 2008-12-06
Age : 29
Location : to bys chtěl vědět co ?.....Czech Rebublic
Country : Czech

AS for beginners Empty
PostSubject: Re: AS for beginners   AS for beginners I_icon_minitimeWed May 27, 2009 2:55 pm

thats great !! it helped me thx :3
Back to top Go down
https://glowanims.forumotion.net
Reaven
Admin
Admin
avatar


Posts : 676
Experience : 10001287
Join date : 2008-12-17
Age : 30
Location : im your neighbor!!!.....naah, im German.
Country : Germany

AS for beginners Empty
PostSubject: Re: AS for beginners   AS for beginners I_icon_minitimeWed May 27, 2009 2:56 pm

glad it helped u :3

edit:
if anyone wants to know how to jump just post here.
Back to top Go down
http://glowanims.ohost.de
Kieran.
V.I.P
Kieran.


Posts : 1233
Experience : 2147483647
Join date : 2009-05-10
Age : 29
Location : England
Country : UK

AS for beginners Empty
PostSubject: Re: AS for beginners   AS for beginners I_icon_minitimeWed May 27, 2009 11:10 pm

Looks like it will help a lot of people. But I'm a pretty lost cause with actionscript.
Back to top Go down
Reaven
Admin
Admin
avatar


Posts : 676
Experience : 10001287
Join date : 2008-12-17
Age : 30
Location : im your neighbor!!!.....naah, im German.
Country : Germany

AS for beginners Empty
PostSubject: Re: AS for beginners   AS for beginners I_icon_minitimeThu May 28, 2009 4:15 pm

lol...thx =D
Back to top Go down
http://glowanims.ohost.de
Reaven
Admin
Admin
avatar


Posts : 676
Experience : 10001287
Join date : 2008-12-17
Age : 30
Location : im your neighbor!!!.....naah, im German.
Country : Germany

AS for beginners Empty
PostSubject: Re: AS for beginners   AS for beginners I_icon_minitimeWed Aug 19, 2009 1:05 pm

updated, added context menu
Back to top Go down
http://glowanims.ohost.de
Res
Admin
Admin
Res


Posts : 1616
Experience : 10002274
Join date : 2008-12-06
Age : 29
Location : to bys chtěl vědět co ?.....Czech Rebublic
Country : Czech

AS for beginners Empty
PostSubject: Re: AS for beginners   AS for beginners I_icon_minitimeWed Aug 19, 2009 2:03 pm

nice tut thanks :3
Back to top Go down
https://glowanims.forumotion.net
Sponsored content





AS for beginners Empty
PostSubject: Re: AS for beginners   AS for beginners I_icon_minitime

Back to top Go down
 
AS for beginners
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
GlowAnims :: Creation :: Tutorials-
Jump to: