Community

AS2 Codes for creating functional game

Posted Jan 31, '10 at 10:37pm

alsage

alsage

124 posts

Wood - Lord

Good Programming Scripts AS2
So a lot of people ask “how do I create games?â€
Well there are many ways to create them. For me I like to use flash. I have decided to make a little forum section on simple but affected scripts for your new flash games. These only work for LINGO scripts.

(I have tested all of the scripts before posting them to make sure I don’t give you false code)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Conditional statements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
YOU ONLY NEED THESE ONCE PER FRAME!

this.onEnterFrame = function()
{
(button type code go in here)
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Button Scripting
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Main Frame Script:
   
yourButton.onRelease = function()
    {
        (your code goes here)
    }

Inside Your Object:

on (release)
{
(Code goes here)
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Arrow Key Movement
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NEEDS CONDITIONAL STATEMENT!

Main Frame:

this.onEnterFrame = function()
{
if(Key.isDown(Key.UP))
{
    yourObject._y -= 10;
}

if(Key.isDown(Key.DOWN))
{
    yourObject._y += 10;
}

if(Key.isDown(Key.LEFT))
{
     yourObject._x -= 10;
}

if(Key.isDown(Key.RIGHT))
{
    yourObject._x += 10;
}
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HitTest Statement
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if(_root.yourObject.hitTest(_root.yourOtherObject))
{
   
    (Code goes here)
   
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mouse rollover & rollout
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Make Sure This Code Is Inside Your Object You Want To Rollover & Rollout!

on(rollOver)
{
(Code goes here)
}

on(rollOut)
{
(Code goes here)
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Code Placement
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Codes for inside of the brackets:

trace("Put random word here ") <- this is used to check to see if your code is working VERY USEFULL!

YourObject._rotation += 10; <- rotates object to the left
YourObject._rotation -= 10; <- rotates object to the right

YourObject._rotation += 10; <- rotates object to specific place
YourObject._rotation -= 10; <- rotates object to specific place

YourObject._width += 10; <- Expands your objects width
YourObject._height += 10; <- Expands your objects height

YourObject._alpha -= 10; <- objects transparency decreases
YourObject._alpha += 10; <- objects transparency increases

YourObject._x += 10; <- moves object to the right
YourObject._x -= 10; <- moves object to the left
YourObject._y += 10; <- moves object downward
YourObject._y -= 10; <- moves object upward

YourObject._x = 10; <- moves object to specific location left to right
YourObject._y = 10; <- moves object to specific location up and down

gotoAndPlay(2);  <- go’s to frame 2 (or any frame # you put in) and plays
gotoAndStop(2);  <- go’s to frame 2 (or any frame # you put in) and stops

YourObject._X = (550) * Math.random(); <- randomly places object on the x axis (needs conditional statement)
YourObject._y = (400) * Math.random(); <- randomly places object on the y axis (needs conditional statement)

EXAMPLE:

this.onEnterFrame = function()
{
char.onRelease = function()
    {

    YourObject._y = (400) * Math.random();
YourObject._X = (550) * Math.random();
           
    }
}

Posted Jan 31, '10 at 10:39pm

alsage

alsage

124 posts

Wood - Lord

sorry I accidently pressed enter so i didnt finish editing

 

Posted Feb 1, '10 at 8:18am

plasmafish

plasmafish

241 posts

Wood - Squire

These are crap IMO.  Basic flash programming learned from any basic flash book.

These scripts are nothing special, a lot is left for interpretation by the reader.

 

Posted Feb 1, '10 at 2:01pm

Louissi

Louissi

68 posts

Gold - Squire

I doubt these scripts would really help anybody since they are all out of context. I guess the best way to elarn is to follow simple tutorials and understand the whole structure of AS.

 

Posted Feb 1, '10 at 2:16pm

plasmafish

plasmafish

241 posts

Wood - Squire

Louissi, I wholly agree.

 

Posted Feb 2, '10 at 6:44pm

alsage

alsage

124 posts

Wood - Lord

I just made them to help others.. i wouldnt expect many to need them

 

Posted Mar 16, '11 at 4:16am

madgoblin

madgoblin

1 post

 -

hey thanks for making these codes... i already know all of them but they still help :0    could you make more complex codes for a platformer game?

 
Reply to AS2 Codes for creating functional game

You must be logged in to post a reply!