Be a Supporter!

useful AS2.0 codes

  • 748 Views
  • 4 Replies
New Topic
flimsystick
flimsystick
  • Member since: Oct. 15, 2011
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
useful AS2.0 codes 2011-11-19 12:55:04

hey guys, i recently got into as2.0 programming and stuff, and i know that many others would like to as well, so.

here is a list of useful codes you can use

mouse follow code

onClipEvent (enterFrame) {
Mouse.hide();
this._x = _root._xmouse;
this._y = _root._ymouse;
}

arrow key movement code

onClipEvent(enterFrame) {
if(Key.isDown(Key.LEFT)) {
this._x -=10;
}
if(Key.isDown(Key.RIGHT)) {
this._x +=10;
}
if(Key.isDown(Key.UP)) {
this._y -=10;
}
if(Key.isDown(Key.DOWN)) {
this._y +=10;
}
}

example:http://www.fileize.com/view/b3da 331a-4b6/

character movement codes

onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var speed:Number = 7;
var maxJump:Number = -12;
var touchingGround:Boolean = false;
}
onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y, true)) {
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y+5, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.UP) && touchingGround) {
grav = maxJump;
}
if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
_x -= speed;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
_x += speed;
}
if (ground.hitTest(_x, _y-(height), true)) {
grav = 3;
}
}

barrier codes

right block

onClipEvent (enterFrame){
if(_root.char.hitTest(this)){
_root.char._x-=10;
}
}

left block

onClipEvent (enterFrame){
if(_root.char.hitTest(this)){
_root.char._x+=10;
}
}

top block

onClipEvent (enterFrame){
if(_root.char.hitTest(this)){
_root.char._y+=10;
}
}

down block

onClipEvent (enterFrame){
if(_root.char.hitTest(this)){
_root.char._y-=10;
}
}

quality and mute button codes

quality

on (press) {
if (_quality == "HIGH") {
_quality = "MEDIUM";
} else if (_quality == "MEDIUM") {
_quality = "LOW";
} else if (_quality == "LOW") {
_quality = "HIGH";
}
}

mute

on(release){
if(this._currentframe == 1){
stopAllSounds()
this.gotoAndPlay("on");
}
else if(this._currentframe == 2){
//unmute
this.gotoAndPlay("off");
}
}

hope you find all these useful and get coding :)

KLT1M
KLT1M
  • Member since: Apr. 13, 2011
  • Offline.
Forum Stats
Member
Level 04
Artist
Response to useful AS2.0 codes 2011-11-19 13:01:05

where can i learn programing, i do not know one thing about the subject so i need alot of help

Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
Response to useful AS2.0 codes 2011-11-19 13:02:37

First off, ActionScript belongs in the Flash Forum.

Second off, there is an entire thread dedicated to stuff like this: AS: Main. (not to mention the countless amount of flash tutorials on this website, as well as thousands of others)

:)


Hello, from the past!
[ PHP: Main ]

BBS Signature
KLT1M
KLT1M
  • Member since: Apr. 13, 2011
  • Offline.
Forum Stats
Member
Level 04
Artist
Response to useful AS2.0 codes 2011-11-19 13:04:25

At 11/19/11 01:02 PM, Momo-the-Monkey wrote: First off, ActionScript belongs in the Flash Forum.

Second off, there is an entire thread dedicated to stuff like this: AS: Main. (not to mention the countless amount of flash tutorials on this website, as well as thousands of others)

)

thanks

deckheadtottie
deckheadtottie
  • Member since: Oct. 21, 2003
  • Offline.
Forum Stats
Supporter
Level 60
Programmer
Response to useful AS2.0 codes 2011-11-19 14:26:41

At 11/19/11 01:02 PM, Momo-the-Monkey wrote: First off, ActionScript belongs in the Flash Forum.

Second off, there is an entire thread dedicated to stuff like this: AS: Main. (not to mention the countless amount of flash tutorials on this website, as well as thousands of others)

)

Well put.


#coys

BBS Signature