12.16.2010

Compile ActionScript file using mxmlc

Steps in compiling ActionScript file (.as) using mxmlc of Flex SDK.

Obtaining the Compiler
- To create SWF files from ActionScript, you will need a compiler, the program that interprets ActionScript code and translates it into the machine code used in SWF files. The compiler used to compile ActionScript or MXML is mxmlc.exe. mxmlc.exe can be downloaded free, just download the latest Flex SDK, and you will obtain the MXMLC.EXE.

MXMLC.EXE - can be found in SDK_PATH/bin/mxmlc.exe.

About mxmlc.exe

mxmlc.exe is a launcher that runs the MXML and ActionScript 3 compiler that converts MXML files (.mxml) and ActionScript 3 files (.as) into published SWF files (for the purposes of this tutorial, we will be primarily concerned with ActionScript 3 files though the compiler handles both as well as some other file types used in the ultimate generation of the SWF). The real compiler is a Java jar file located in the lib directory of your Flex Builder/SDK install and not mxmlc.exe itself. Because of this, to work with the compiler you'll A) need to make sure you keep all of those files of which the compiler is dependant (i.e. dont go moving around just mxmlc.exe and expect it to work), and B) need to have the Java runtime environment installed on your system. If you've installed Flex Builder you won't have to worry about this since it will take care of this for you. If you just got the SDK, however, and haven't had Java installed on your computer, you can download and install the Java runtime environment from http://java.sun.com.

In the directory containing mxmlc.exe you may notice some other executables. compc.exe is for creating SWC files (pre-compiled component file), and fdb.exe is the command line debugger. Here we are sticking to just using mxmlc.exe which is all you need to get started using ActionScript 3.

For mxmlc command line options, just visit http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_13.html

How to compile ActionScript in mxmlc
- create a batch file. Here is a sample of batch file I used for compiling fonts.
C:\flex_sdk_4.1.0.16076\bin\mxmlc.exe -o output.swf -source-path=C:\_cafepress\devtools\manila\fonts\src\ C:\_cafepress\devtools\manila\fonts\src\font\Alepholon.as

- the ActionScript file (I used Alepholon.as here)
package font
{
import flash.display.Sprite;
import flash.text.Font;

/**
* Font library
* @author mykhel
*/
public class Alepholon extends Sprite
{

[Embed(source='../../lib/Alepholon.ttf'
,fontFamily ='Alepholon'
,fontStyle ='normal' // normal|italic
,fontWeight ='normal' // normal|bold
,unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'
,embedAsCFF='false'
)]
public static const fontClass:Class;

public function Alepholon()
{
Font.registerFont(fontClass);
}

}

}

Note: This class is to embed font. I get this sample in one of the output file of automation tool in converting Font file (.TFF) into SWF that I have created.

- Run the batch file, and look for the output file. In my example, output file can be found in the directory of the batch file.

Download the sample files here.
Please note, I cannot include the Alepholon font, but you can try the other font. Play around with the batch file, change the path and options.

Original story here.

6.22.2010

Color Spectrum Chart AS3





Color Spectrum Chart is a AS3 tool for creating different types of color spectrum chart. It is very useful for custom color picker. This class includes ColorUtils class, another class which is useful in manipulating colors.

This is PURE CODE and PURE CALCULATION, using pixels and arrays. Absolutely no images embeded. This only requires 2-kb of filesize, and the speed is well analyzed and it is very fast.

I have no liable in other color spectrum charts or others. This class is purely coded and no tools, besides with FlashDevelop, has been used. I'm sharing this to others with no charge. Again, The images (Bitmap) that comes out after finishing this tool was not intended to copy with the others. It is only how it was output by the algo.

The AS3 file is documented well, and will easy to be use by other developer. The tutorials is in the class itself as well as in the ColorUtils class.

Source code here. (used FlashDevelop, if using Flash IDE/FLEX, just copy the src foloder and use the Main.as)
Demo here.

3.22.2010

Free 3D Panorama

Download free 3D Panorama view. I include the source code and sample files. Open the source code and play to learn more about 3Ds. I used the GreenShock's TweenLite engine for tweening animation, and Away3D for 3d engine. It is ready to use, just set the image in the flashvar to change the image.

Explanations are in the source code. Use imagePath for the flash var in HTML.

Sample flashvar:
"imagePath=test.jpg"

Credits to:
GreenShock's TweenLite - for tween engine.
Away3D - for 3d engine.

Download: (im using flashdevelop and AS3)
Free 3D Panorama

Demo:
Free 3D Panorama

If you need help, contact me through my email: mykhel0003 [at] gmail.com

3.03.2010

AS3 Tip of the Day - Saving XML/text using Flash/PHP

This tutorial will show how to save XML or TEXT file in your server using FLASH and PHP.

This is very helpful to me and I have used this many times. In one of my first project using this kind of functionality, I researched in the net, and found this solution.

AS3:

// declaring var xmlcontents String. You should set this first.
var xmlcontents:String = "this is the xml contents to be saved in your xml."

// declaring var foldername String. This is the folder container of the saved XML file
var foldername:String = "myXML."

// declaring var filename String. This is the filename of the XML file
var filename:String = "test.xml."

// declaring var dataPass URLVariables
var dataPass:URLVariables = new URLVariables();

// declaring var urlLoader URLLoader
var urlLoader:URLLoader = new URLLoader();

// declaring var previewRequest URLRequest
var previewRequest:URLRequest = new URLRequest(Main.SERVER_PATH + "saving-xml.php");

// i used method "post" in this sample. you can edit this
previewRequest.method = URLRequestMethod.POST;

// setting dataPass variables to be passed to PHP
dataPass.filename = filename;
dataPass.xmlcontents = xmlcontents;
dataPass.foldername = foldername;

// passing dataPass data PHP
previewRequest.data = dataPass;

// calling the PHP or loading the PHP
urlLoader.load(previewRequest);


PHP:

// POST variable
$fileName = $_POST["filename"];

// POST variable
$xmlContents = $_POST["xmlcontents"];

// backslashes from xml string (skip this for plain text)
$lastBackslashPos = strpos ($xmlContents, "\\");
while($lastBackslashPos >0){
$xmlContents = substr($xmlContents,0,$lastBackslashPos)
.substr($xmlContents,$lastBackslashPos+1,strlen($xmlContents));
$lastBackslashPos = strpos ($xmlContents, "\\");
}

// POST foldername
$foldername = $_POST["foldername"];

// test if the folder name is existing in the server (skip this if you want to test in server path)
if(!is_dir($foldername . "/")) {
mkdir($foldername . "/", 0755);
}

// write xml data to file on server relatively to server path of the this PHP file
$fh = fopen($foldername . "/" . $fileName, "w");
fwrite($fh, $xmlContents);
fclose($fh);
?>

Many thanks to Google.

AS3 Tip of the Day - Matrix

To those who are not yet familiar with the AS's Matrix Class, you can Google it and get yourself familiarized with it.

- If you wan't to know the matrix properties of a DisplayObject:
Example you have mc1 and mc2 in stage, and you want to copy the exact position, rotation, scale of mc1 to mc2.

var mtrx:Matrix = new Matrix();
mtrx = mc.transform.matrix; /// if you have mc in your stage, and you want to clone it's matrix and set it to other objects.
trace(mtrx);
mc2.tranform.matrix = mtrx;


cheers,
- mykhel :D

Bula Game


Game Profile








Bula Game


BulaBULA, bubble collecting game. Avoid falling black pearls and wondering fishes. Collect gold and white pearls to protect the BULA.

  • Game Dimensions: 500x460

  • Primary Category: Adventure

  • Categories: Action

  • Keywords: fish, collecting game, action game, free game, arcade game, flash game, bula, bubble, pearl

  • Rating: Everyone

  • Developer: Mykhel Trinitaria


Just added in MPTGAME.COM for sponsorship. Visit here for more strategy games,or click on the link here for more games.

AS3 Tip of the Day - flashvar

I'm creating an web flash application which requires SESSIONs if the user is login or not.

How I do it? I simply used a "flashvar" to detect if the user is login or not.

to get the parameters in flashvar see sample:

in HTML:
src="testflashvar.swf"

quality="high"
bgcolor="#000000"
width="500" height="300"
flashvars="userid=mykhel trinitaria"
name="testflashvar"
align="middle"
play="true"
loop="false"
quality="best"
allowScriptAccess="always"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">



in FLASH:

var userid:String = root.loaderInfo.parameters.userid
trace(userid); // "mykhel trinitaria"


AS3 Tips of the Day - LocalConnection AS3

AS3' LocalConnection is just the same as in AS2, only differences is the event listeners. This can be useful when it needs to communicate a AS2 to AS3, because we can't loadmovie a AS2 to AS3, or vice versa. There are other ways to use this. Hope my simple example can help others.

Sender:

package {
import flash.display.*;
import flash.events.*;
import flash.net.*;

public class Sender extends MovieClip {
private var send_lc:LocalConnection;
private var params:String = "my name is mykhel";
public function Sender():void {
/// instantiate send_lc
send_lc = new LocalConnection();

/// should have status event for testing purposes
send_lc.addEventListener(StatusEvent.STATUS, onStatus);

/// send to receiver a connection id and methods with params
/// .toString() just to make sure the receiver will be accepting a String
send_lc.send("connectId", "callBackFunction", params.toString());
}

/// instantiate rcv_lc
private function onStatus(evt:*):void {
switch (evt.level) {
case "status":
trace("LocalConnection.send() succeeded");
break;
case "error":
trace("LocalConnection.send() failed");
break;
}
}
}
}


Receiver:

package {
import flash.display.*;
import flash.events.*;
import flash.net.*;

public class Receiver extends MovieClip {
private var rcv_lc:LocalConnection;
public function Receiver():void {
/// instantiate rcv_lc
rcv_lc = new LocalConnection();

/// setting rcv_lc client to this
rcv_lc.client = this;

/// i put in a enterframe event the connect, i used this in a tandem simultaneous connect
addEventListener(Event.ENTER_FRAME, function ():void {
try {

/// rcv_lc connect with connectId (this should be unique id)
rcv_lc.connect("connecId");

} catch (error:ArgumentError) {
trace("Can't connect...the connection name is already being used by another SWF");
}
});
}

/// function to be execute passed from LC sender.
public function changeImage(str:String):void {
trace("LC CONNECTED. PARAMS: " + str);
}
}
}

AS3 Tips of the Day - removeChild()

Our Tip of the Day is DisplayObjectContainer's removeChild() method:

AS3's method removeChild() is a method of DisplayObjectContainer and Inheritance by:
-> DisplayObjectContainer -> InteractiveObject -> DisplayObject -> EventDispatcher -> Object.
-> import flash.display

removeChild() method is not the same as AS2's removeMovieClip(). This are the difference of removeChild and removeMovieClip:
1. removeChild will output and error if you use removeChild in a null object. While removeMovieClip will just ignore if there is a null.

Well, to avoid this error, here are some tips to use removeChild():
1. If you need to isntantiate a movieclip by removing it to stage before adding, but this depends on the instance. I always use this method (removing child before adding child, in some instances)
package {
import flash.display.*;
import flash.events.TimerEvent;
import flash.utils.Timer;

public class Main extends MovieClip {
var arr:Array = new Array()

public function Main():void {
/// creating Timer instance t
var t:Timer = new Timer(1000, 0);

/// add event listener to Timer t, and has a callback function onTimer()
t.addEventListener(TimerEvent.TIMER, onTimer);

/// start the Timer t
t.start();
}

/// callback function onTimer for Timer t
private function onTimer(evt:TimerEvent):void {
/// if arr.length > 5 all movieclips on stage will be removed
if (arr.length > 5) {
/// this is how to removeChild in a stage, by putting a child in a Array
for (var i:int = 0; i < arr.length; i++) {
removeChild(arr[i]);
}
/// will need to instantiate the Array arr
arr = new Array();
}

/// will need to instantiate the Array arr
var mc:Sprite = new Sprite()
mc.graphics.beginFill(Math.random() * 0xffffff);
mc.graphics.drawCircle(Math.random() * 100, Math.random() * 100, Math.random() * 20);
addChild(mc);

/// push the mc in a Array.
arr.push(mc);
}
}

}

2. removeChild by 'name'
/// addChild mc with name "myMc".
var mc:Sprite = new Sprite();
mc.name = "myMc";
addChild(mc);

Iif you want to remove the child by name used:
removeChild(getChildByName("myMc"));

3. To remove directly the instance, but if you don't know if the instance is in the stage, just use try/catch methods:
try {
removeChild(mc);
} catch (err:Error){}

2.13.2010

MPTGAME.COM

MPTGAME.COM now reaches 2000+ free online games and almost 17000+ played games in just 1 month. This is a proof that MPTGAME.COM is now ready to fly. If you are bored and stressed, just visit the websites and play more than 2000+ free online games. Click here to subscribe for the latest free online games.

MPTGAME.COM has sponsored 3 games.
The Turret Bot Defense - has a very good graphics and another addicting tower defense.
Freelancer Tower Defense - has a unique tower and maps.
Alien Bug Invader - an old arcade game which reloaded by MPTGAME.COM

MPTGAME.COM has now 34 categories.
List of categories and games per categoy (feb. 13, 2010):

To subscribe just click here.

2.06.2010

Arcade Banner Exchange

Tired of promoting your arcade sites by commenting to other pages? Well this is the solutions of how to spread and promote your sites. Register for free, and you got free impressions. If you want more impressions, they offer cheap packages and you should try it.

Here is the list:

Promise! You won't regret, because they have thousands of partners and millions of users. You can also edit your own banner. It should be 100x100 or 125x125 .jpg or .gif format. I prefer GIF format because it animates and can attract users to click the ads.

Please take a look of my sample arcade exchange banner, this was register by Mykhel Trinitaria for my website mptgame.com:




















If you are looking for arcade site which you want to sponsorized, just visit here.

2.02.2010

Turret Bot Defense on MPTGAME.COM


Game Profile









Turret Bot Defense


Defend the base from the waves of mob by building tanks and turrets on the terrain. This is addicting tower defense game

  • Game Dimensions: 640x520

  • Primary Category: Strategy

  • Categories: Action

  • Keywords: tower defense, td

  • Rating: Everyone

  • Developer: Mykhel Trintiaria


Just added in MPTGAME.COM for sponsorship. Visit here for more strategy games,or click on the link here for more games.