Monday, January 19, 2009

How to Run Your Game From Your Server Only?

Suppose you made your own flash game and want it to be played from your server only and no where else on the internet.

This code may help you:

__________________code start____________________

if (this.root.loaderInfo.url.indexOf("YOUR SITE GOES HERE") != -1) {
//OK THATS WHAT I WANT
}
else {
var myURL:URLRequest = new URLRequest("YOUR SITE GOES HERE");
navigateToURL(myURL);
//if the game is not played from my server redirect the player to my site!
}

__________________code end____________________

Description of the code:

We are using the this.root.loaderInfo.url property that returns the full path of the SWF file, starting with http:// , so we are checking if the path of the game has your web address in it or not. It will return -1 if it doesnt and will return a positive value if it does.


1- if (this.root.loaderInfo.url.indexOf("YOUR SITE GOES HERE") != -1) {
//OK THATS WHAT I WANT
}


The value is not -1, so the game is running from my server.

2- else {
var myURL:URLRequest = new URLRequest("YOUR SITE GOES HERE");
navigateToURL(myURL);
//if the game is not played from my server redirect the player to my site!
}


The value is -1, then someone downloaded the game and running it from his server so you will need to redirect the player to the original place of the game which is your website, the following two lines will do that

var myURL:URLRequest = new URLRequest("YOUR SITE GOES HERE");
navigateToURL(myURL);



You can do this check before the game starts, if it is running from your server then start the game, otherwise dont start the game and redirect the player to your website.

Learn more about game protection here

Sunday, January 18, 2009

Protect Your Flash Game From Decompilers

Go to google and search for flash file decompilers, you will find many programs that allow others to download and modify flash files.

The basic way to protect your flash file from being modified while it is on the internet is to enable the Protect From Import and Compress Movie
options, you can do that by going to:

1- File






2- Publish Settings








3- Flash Tab
4- Check the Protect From Import and Compress Movie boxes.
5- In the Password field enter a password, so that if anyone wanted to import your flash file it will ask for password.





















This will make it difficult for decompilers to decompile your flash file, but still there are many decompilers that can decompile protected flash files.

The other way is to encrypt your flash file by using one of the encryption tools, so that if someone downloaded your flash file the code inside it will be encrypted and the downloader will not be able to understand anything from the code.








One of the new and free tools is MochiAds Version Control and Encryption, mochiads say about it:

" Version Control and Encryption is a hot, sexy new way to be able to update your SWFs live and protect them from prying eyes. All the cool kids are doing it! ".

To try mochi's hot, sexy new Version Control and Encryption:

1- Go to https://www.mochiads.com/ .

2- Sign Up if you are not and then Log in.

3- Scroll down to the bottom of the page and click on " SETUP NEW GAME "





4- In the "Title" field enter the name of the game




5- In the "Dimensions" filed enter the (widthxheight) of the game.




6- In "Version Control" choose "Yes" to install the Version Control and Encryption tool into your game.



7- Click on "CREATE GAME" .





8- Under "Authenticate Your Game:" there is a code
" var _mochiads_game_id:String = "##################"; ", copy it and paste it in any place in your game and run the game. This way mochi will know that your are the owner of the game.






9- Under "Style your New Preloader Ad:" choose the style of the preloader that matches your game.













10- Under "Upload your game SWF:" upload your SWF file that has the code in, enter the version number of the game and description of the uploaded file.












11- Click "UPLOAD GAME" .

Now mochi will make sure that the code is in the SWF file and will generate an encrypted SWF out of the SWF you uploaded!

If everything is ok, you will see this











Download the file, inside it you will find the encrypted SWF!

This is not the only way to that, the internet is full of code encryption tools that do the same job, but this one in my opinion is the easiest to use!

I hope that this post helped you,,
Have a nice day..

Saturday, January 17, 2009

AS3 Loading Screen ( Preloader )

Why do we need loading screen?

Flash is built for streaming content, which means the movie will start if the minimum bare content has been loaded, such as elements used in the first frame.
This will not be good in games, because if a part of the game didnt load, then the game may not work properly!
So we need to dedicate a frame at the beginning of the game to load the whole game parts on and after the loading is done, we will allow the game to start.

The following code will show you how to do that:

__________________code start____________________

stop();

addEventListener(Event.ENTER_FRAME, loadProgress);

function loadProgress(event:Event) {
// get bytes loaded and bytes total
var movieBytesLoaded:int = this.root.loaderInfo.bytesLoaded;
var movieBytesTotal:int = this.root.loaderInfo.bytesTotal;


// convert to KiloBytes
var movieKLoaded:int = movieBytesLoaded/1024;
var movieKTotal:int = movieBytesTotal/1024;
var percentageLoaded:Number=Math.round((movieKLoaded/movieKTotal))*100;


// show progress
progressText.text =""+percentageLoaded+"% Loaded";

// move on if done
if (movieBytesLoaded >= movieBytesTotal) {

removeEventListener(Event.ENTER_FRAME, loadProgress);

gotoAndStop(2);

}
}

__________________code end____________________


Description of the code:

1- First you need to add " stop(); " at the begining to stop the movie at the loading page.

2- Add an event listener that will apply the loadProgress function to all frames "addEventListener(Event.ENTER_FRAME, loadProgress);"

3- The first two lines in the loadProgress function are

var movieBytesLoaded:int = this.root.loaderInfo.bytesLoaded;
var movieBytesTotal:int = this.root.loaderInfo.bytesTotal;


" this.root.loaderInfo " is used to get the status of the movie, so in the first line it will get the loaded bytes of the movie and in the second line it will get the total bytes of the movie .

4- Lines 3 and 4 in the function are

var movieKLoaded:int = movieBytesLoaded/1024;
var movieKTotal:int = movieBytesTotal/1024;


In this step we are converting the loaded bytes to kilobytes, because they will be needed in the next step when calculating the loading percentage .

5- Line 5 in the function is

var percentageLoaded:Number=Math.round((movieKLoaded/movieKTotal))*100;

In this step we are calculating the percentage of the loaded bytes.
First divide the loaded kilobytes over the total kilobytes of the movie, that will give us the ratio of the loaded bytes over the total bytes of the movie. Then we need to round the result to not have fractions in the percentage. After that we multiply the result by 100 and that will give us the percentage of the loaded bytes.

6- Line 6 in the function is

progressText.text =""+percentageLoaded+"% Loaded";

In this line we are showing the percentage loaded movie to the user.
I made a dynamic text field on the stage and named it progressText, so by using
progressText.text we are editing the content of the text field and entering the percentage in it.
Note: progressText.text accepts only strings, so I added ( ""+ ) after it which means deal with everything after me as string!

7- Line 7 in the function is

if (movieBytesLoaded >= movieBytesTotal) {
removeEventListener(Event.ENTER_FRAME, loadProgress);
gotoAndStop(2);
}

Now we are checking if the bytes loaded are larger than or equal to the total bytes, if so then the loading is done.
When the loading is done, we will need to do two actions:

>Stoping the loadProgress listener.
>Moving to the frame that the game starts on (in my case im assuming that the game starts on frame 2).

THATS IT!

Here is the source file

Friday, January 16, 2009

Saving Local Data





Local data is used to save data into the user's machine such as score,level number,..etc.

On the top of this post I made a simple counter that counts how many times did the visitor visit my blog!

Here is the code for it

__________________code start____________________

var count:int;//the counter variable
var myLocalData:SharedObject = SharedObject.getLocal("mygamedata");//making a local shared object

var myData:String=""+myLocalData.data.storedInfo;//adding the info in the shared object to myData

if(myData=="undefined")//if there is no stored data before in the shared object it will return undefined
myLocalData.data.storedInfo=1;//store one because this is the 1st visit

else//if this is not the 1st visit increment the value of the shared object by 1
++myLocalData.data.storedInfo;


count=myLocalData.data.storedInfo;//assign the value of the shared object into count
counter.text=""+count;//write the vaalue of count

__________________code end____________________

Here is the source file

Enjoy it!!

Thursday, January 15, 2009

Protect Your Game From Right Clicks!!

Right click any flash file, a menu will show up with many items, in the middle you will find "Rewind" and "Forward", those two items allows the user to move from frame to frame in the flash file.







This will be a bug in the game or an easy cheat for players to jump from level to level if each level of the game has its own frame.

The solution is to disable right clicks, as in the example below:





The following code shows you how to do that:

__________________code start____________________

var menu:ContextMenu = new ContextMenu(); //Instance of ContextMenu menu.hideBuiltInItems(); //Hide the default items

var item1:ContextMenuItem = new ContextMenuItem("All rights reserved");//Creating an item

menu.customItems.push(item1);//Adding the item to the menu

this.contextMenu = menu;//Apply our menu plz!

__________________code end____________________

This code will remove the items from the menu and add an item that says "All rights reserved".

You may creat new items and push them to the menu.

Write this code in the first frame in your flash file to disable right clicks in all frames.

Download the source file

Enjoy !


MindJolt API








MindJolt says there are 4 ways to install the API, 3 of them using components and the last one is manually done using action script, lets take a look at them.

Note: If you dont want to deal with adobe extensions jump to step 3.

Installation using components (highly recommended):

1-MXP

-Install Adobe Extension Manager .
-download the MXP component.
-After installing the extention, run it and goto file>Install Extension and choose the MindJoltAPI component.
-Now go to your flash file and go to Window>Components and you will find the component under the name MindJoltAPI drag it and drop it on te stage.

2-SWC

If you dont want to download the extension manager do the following:

-Close adobe flash
-Download the SWC File.
-Follow this path C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Components\ in Components create a new folder and name it MindJolt and paste the SWC file inside it.
-Now open flash and go to Window>Components and you will find the component under the name MindJoltAPI drag it and drop it on te stage.

3-FLA

If you dont want to deal with adobe extensions, then do the following:

-Download the Sample FLA File .
-Open it and copy the MindJoltAPI component from the library and paste it in your flash file.


Manual installation by using actionscript code snippet:

4-Action Script

Below is a code snippet that will load the API manually.

This code snippet needs to happen as EARLY as possible when your game starts.
You will need access to "root" to be able to get the path to the API that we'll pass in via FlashVars.
After you lead the API from that path, you need to keep track of the API instance yourself, so you have it when you want to submit the score.

__________________code start____________________

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;

// You'll use this variable to access the API
// (make sure you can access it from wherever you will later call submitScore)
var MindJoltAPI:Object;



//////
// All of this code should be executed at the very beginning of the game
//

// get the parameters passed into the game
var gameParams:Object = LoaderInfo(root.loaderInfo).parameters;

// manually load the API
var urlLoader:Loader = new Loader();
urlLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadFinished);
urlLoader.load(new URLRequest(gameParams.mjPath "http://static.mindjolt.com/api/as3/scoreapi_as3_local.swf"));
this.addChild(urlLoader);
function loadFinished (e:Event):void {
MindJoltAPI=e.currentTarget.content;
MindJoltAPI.service.connect();
trace ("[MindJoltAPI] service manually loaded");
}
__________________code end____________________


How to use it!!!

Now that you have the API installed through one of the above methods, you need to get access to it in the code to submit the score.
If you are using one of the components, you can get access just by using the import statement below. But, if you were using the manual code snippet, then you'll have to get access to the MindJoltAPI variable you declared in the script instead.

import com.mindjolt.api.as3.MindJoltAPI;

Then add the line of code that will submit the score.
You simply need to provide the score. And, if you use game modes, you should provide the current mode the player is playing in. (Example game modes: "easy", "normal", "hard", etc.)
The submitScore call should be placed wherever you compute the final score for the game.

For example, suppose you store the score in a variable called "currentScore".

1-Submitting a score without a game mode

MindJoltAPI.service.submitScore(currentScore);

2-Submitting a score with a game mode

MindJoltAPI.service.submitScore(currentScore, "easy");


Only put in a game mode if you have more than one mode in your game. This allows us to track the high scores for each game mode separately.


for more info visit MindJolt API

Kongregate API

Kongregate shares 25% of the revenue with the developers from their games.

If Kongregate's API is added to the game, 10% will be added to the revenue, if the game is offered exclusively to Kongregate then 15% will be added.

Thats 50% of the game's revenue!!

Steps for installation are on Kongregate's API

Enjoy!!

Hallpass API






I will summaries what Hallpass say about their API:

-50$ for each API added to a game, ofcourse after the game is approved by Hallpass.
-They will pay you via PayPal after your game is uploaded to their site.
-The API will send the scores to Hallpass, and they will be tracked in the users profiles.
-The scores must be submitted at the end of each level or game.

Here are the steps to add the API:

1-Add the API Code to your game.
2-Upload it to Hallpass.
3-Wait a few minutes then check your profile area, your game should appear. Play and test your game out to see if it is sending us scores, be patient as scores update every few minutes... so play, wait, then check.
4- Email us that your game has worked and you want to get paid, include your pay pal address.


for more info visit Hallpass API

Wednesday, January 14, 2009

Where to Submit your Flash Game?

You just finished your game and tested it and everthing is OK and now you want to publish it. I advice you to first upload the game onto (www.kongregate.com/) and (www.newgrounds.com), because they are the most known flash game portals that accept game submissions from developers and have big amount of traffic.

After that you may search for flash game portals that accept submissions from developers.Here is a list of websites that accept game submissions, some of them will require registration.

Note: If the website asked for "Flash URL", upload the "SWF" file of the game on your website and enter the address of the "SWF" file in the field or make a site using google sites and upload the file there if you dont have a website .

http://www.gamegum.com/submit/
http://www.pnflashgames.com/module-pnfgSubmit.phtml
http://www.itsgamertime.com/submit.php
http://www.gamerfan.com/play/submit/form/index.php
http://www.gotoandplay.com/submit-flash-content/
http://www.free-flash-games.com/submit.html
http://www.gs4.net/index.php/submit/form/
http://howler.com/index.php?params=submit/form/
http://www.gameshandbook.com/submit.php
http://www.igarchive.com/user/addgame_nonemember.php
http://www.thegreatestarcade.com/submit.php
http://addictinggames7.com/submit.htm
http://www.onlinegamesrus.com/submit.php
http://www.bigfootgame.com/submit/
http://www.mypuzzlesgames.com/submit.php
http://www.dontgetpwned.com/index.php?page=submitgames&add=1
http://www.clickhereplaygames.com/submit.php
http://greatinternetgames.com/submit.php
http://www.smashingames.com/submit.php
http://www.gr8games.eu/upload.html
http://www.dcflashgames.com/index.php?title=Upload_file
http://mochi.omgames.co.uk/submit.php
http://www.multigames.com/upload
http://www.stormvideogames.com/index.php?go=submitgame
http://z-fox.com/submit.php
http://www.ussgames.com/newgame.php
http://www.lorenzgames.com/submit.php
http://www.onlypoints.com/arcadeindex.php/submit/
http://www.thegameslist.com/mgl/addgame/nameit
http://allgamesallfree.com/?id=upload

http://multimedia.md/games/submit/form.html
http://www.gamekrunch.com/submit
http://2dum2kno.com/?page_id=22
http://www.freeonlinegames.com/submitagame/index.php
http://www.fupa.com/submit.aspx
http://firecade.com/index.php?action=submitgames
http://www.webgamesnetwork.com/submit.php
http://www.playzgame.com/online-flash-games/submit-your-game.php
http://www.orkgames.com/submit/
http://www.abcarcade.com/submit.html
http://www.thisarcade.com/submit.html

And here is a list of Emails of flash game portals that accept submissions through emails, in this case you will need to make a folder containing the "SWF" file and a 100x100 (jpg, gif and png) thumbnails of the game. Zip the folder and copy the following emails and paste them into your email and send!

3cr@dabontv.com,
AGgames@addictinggames.com ,
blitzgamer.com@gmail.com ,
dabontv@gmail.com ,
AGgames@addictinggames.com,
blitzgamer.com@gmail.com,
captinmorgn@bellsouth.net ,
chris1335@hotmail.com ,
colorin@caracol.com.co ,
developers@mindjolt.com ,
enquiries@mousebreaker.co.uk ,
fifadicto@yahoo.es ,
flashgame.net@gmail.com ,
freegamesnews@gmail.com ,
game@2flashgames.com ,
gamedev@miniclip.com ,
gamegod@freearcade.com ,
gameprison@gmail.com ,
gamesolo@gmail.com ,
info@bigwigmedia.com ,
info@bubblebox.com ,
info@freegamesjungle.com ,
info@hatekonyan.hu ,
info@startgames.ws ,
info2007@coffeebreakarcade.com ,
jobs@mousebreaker.co.uk ,
KST_Admin@killsometime.com ,
mikemaxgames@gmail.com ,
minijuegos@gmail.com ,
onlinegamesflash@yahoo.com ,
plemsoft@plemsoft.com ,
selfdefiant@melting-mindz.com ,
sponsor@gimme5games.com ,
submissions@smileygamer.com ,
t45ol.com@gmail.com ,
tom@thorgaming.com ,
vorarg@comcast.net,
webdesign@info.lt ,
webmaster@flashninjaclan.com ,
webmaster@gamegarage.co.uk ,
webmaster@gamesportal.org ,
webmaster@gametheflash.net ,
webmaster@hispajuegos.net ,
webmaster@smashingames.com ,
webmasterp@jeux-internet.com ,
webmaster@thaiza.com ,
wepinc@gmail.com ,
yourclueless@gmail.com

Good Luck!

Tuesday, January 13, 2009

Market your flash game using facebook applications!


This will not require any programing effort at all.

What you have to do is the following:


1- Upload your "SWF" file onto a host .

2- If you dont have a host use google sites (
http://sites.google.com/) to host your game on, simply sign up and create a site, use the attachment to upload your "SWF" on the website. After uploading the game right click on it and go to properties and copy the URL Address there.

3- Go to (http://www.clearspring.com/) and sign up.

4- After signing up, sign in and click on "Add Widget".

5- click on "In My Widget".

6- Select "Flash" for the wigdet type.

7- Choose the version of your Action Script, 2 or 3.

8- In Flash URL Enter the address of your "SWF" file (or Paste the address you copied from your google site). A box will appear below the URL choose "No thanks" .

9- Enter the title of your game.

10- Select "Games" for category.

11- Click Save Widget.

You will be transfered to a new page says at the top "Congrats! You added your Widget!".

12- click on "Publish Your Widget".

13- Choose "Facebook App".

14- It will ask you "Do you have your own application, or do you want to use our wizard?", choose "No" if you dont have an application on facebook and click next.

15- Go to http://www.facebook.com/developers/ and login to facebook.

16- Click on "Set Up new Application" and click next in the site.
Now follow the steps on the site, if you notice there is a facebook window below each step which you can use rather than using a different window for facebook.

17- After finishing step 7, you will be taken to a new page. next to "Publish as Application" choose "Enable" to enable your application on facebook and save.

18- At the end of the page you will find your application's URL next to "Bookmark URL".

Congrats, you just made a facebook application out of your flash game. You can use this website to distribute your game to many social networks like Myspace,Bebo,Hi5,... .



Saturday, January 10, 2009

Welcome!

Hi everyone, welcome into my blog!
My name is waleed and im intersted in flash game development.
I made 2 games untill now Sky MazezZ (http://www.waleez.co.cc/SkyMazezZ.html) and EyeBall MazezZ(http://www.waleez.co.cc/EyeBallMazezZ.html) which is sold to ugoplayer.com.
The discussion in this blog will be mainly about flash games tricks and tutorials.

mmm....and this is the end of my first post!!