Movie Clip Positioning on Stage controller

Posted February 26th, 2010 in Flash Component, Portfolio by Jimi Sulaiman

Updated! Now available in Actionscript 2.0 and Actionscript 3.0. Custom built in Function for easier control of movieclip positions on the movieclip’s stage.

Usage Example

Actionscript 2.0

registerMc = [movieclipA,movieclipB];
positionMcOnStage(movieclipA,"TC"); //position myMovieclip to the top-center of your stage.
positionMcOnStage(movieclipB,"BL");

Acionscript 3.0

//import the Controller class
import com.jimisulaiman.tween.*;
//initialize the controllers
var myMcController:Controller = new Controller(myMovieclip);
//tween movieclip!
myMcController.positionMcOnStage("C");

With AS3 version, you don’t need to add stage listener into the timeline/frame; Its all built-in into the class.

Click here for demo

Click here to buy

  • Share/Bookmark

AS3 Preloader

Posted February 16th, 2010 in Actionscript 3.0, Codes, Flash Component, Source Files by Jimi Sulaiman

Another Flash Preloader created today. Click on image to try.

In this example, the preloader will appear when the method loadMovieToContent is called from the button click event. Simply set the swf file or the image to be loaded as the parameter for this method.

The source code:

package com.jimisulaiman
{
	import flash.display.Sprite;
	import flash.events.*;
	import flash.display.MovieClip;
	import flash.display.Loader;
	import flash.net.*;

	/*
	Code by jimisulaiman.com on 16 February 2010
	*/

	public class Preloader extends Sprite
	{
		//constructor
		public function Preloader()
		{
			//add listeners to the button
			load_swf_btn.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);
			load_img_btn.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);
			//on loaded, hide preloader
			myPreloader.visible = false;
		}

		//set variables
		var perLoaded:Number = 0;
		var loader:Loader;

		//initialize
		protected function initHandler(event:Event):void
		{
			//show preloader, reset back to zero
			myPreloader.visible = true;
			perLoaded = 0;
		}
		//using onEnterFrame might comes in handy, so I'm just gonna use it here
		protected function enterFrameHandler(event:Event):void
		{
			//set the percentage text%
			myPreloader.per.text = perLoaded + "%";
		}
		protected function progressHandler(event:ProgressEvent) {
			//calculate the percentage loaded
			perLoaded = Math.round((event.bytesLoaded/event.bytesTotal)*100);
			trace("progress:  "+perLoaded+"%");
		}
		private function completeHandler(event:Event):void {
			trace("completed!");
			myPreloader.visible = false;
			//place the loaded movieclip to the content area
			myContent.placer.addChild(loader);
		}

		public function loadMovieToContent(mymovie:String):void {
			trace("Loading "+mymovie);
			//new loader everytime
			loader = new Loader();
			//add those listeners
			loader.contentLoaderInfo.addEventListener(Event.OPEN,initHandler);
			loader.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressHandler);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
			//load it!
			loader.load(new URLRequest(mymovie));
		}

		//set the buttons behaviour
		protected function clickHandler(event:MouseEvent):void
		{
			switch( event.target )
			{
				case load_swf_btn:
				    //trace("button clicked!");
				    loadMovieToContent("content/myswf.swf");
					break;
				case load_img_btn:
				    loadMovieToContent("content/image.jpg");
					break;
			}
		}

	}

}

Download full source code here:  AS3 Preloader (61)

  • Share/Bookmark

Latest Flash Project

Posted February 16th, 2010 in Personal Ramblings by Jimi Sulaiman

The third version is now on its way. I’ve been meaning to upgrade all my files to AS3(Actionscript 3.0) since last year but was reluctant I was thinking that I’m gonna need to learn this new programming language all over again. But to my surprise, it wasn’t that bad after all. In fact,  its easier to learn and so much faster(in performance) and cleaner coding style(just love the OOP style)

So far here’s what I’ve done: http://jimisulaiman.com/example/15022010/test01.html

  • Share/Bookmark

Using Ajax to validate form

Posted February 6th, 2010 in Javascript, PHP, Source Files, Uncategorized by Jimi Sulaiman

There are times where you need to validate a form to a data stored in a database without the need to submit the form beforehand. The solution -

Ajax (shorthand for asynchronous JavaScript and XML).

For example, you are creating a user registration form where obviously, the username to choose from needs to be unique. Instead of validating the username after form submission, wouldn’t it be much friendlier if the form can validate itself  from the server asynchronously in the background from a simple event such as on submit or unfocus event?

In this post, I will be showing how you can the validate with Ajax using PHP/MySQL as your back-end. A table called user is created in the MySQL database which contains some dummy usernames.  When user enters a username existed from this table, the form will prompt an error with message “Username already taken. Please try a different username.”

What you need:

- jQuery 1.4, my favourite javascript library. Click here to download
- jQuery plugin, Validation 1.6. Click here to download
- PHP and mySQL enabled web server (for this example, I’m using PHP 5 and MySQL 5)

You’ll gonna need two files:

- form.php < this will be your form
- check_username.php < this will check  if data exist in the user table in your MySQL database

Link jQuery and the plugin to the form page first.  You can refer to the source file(link at the bottom of this post) if you are not clear on how to do this.  Then add the javascript code below and you’re done on this page.
I’ve commented the code below to explain what each line does.  I’m not gonna touch on the Validation plugin here but if you are interested, you can view its Documentation available from the download site.


$(document).ready(function() {

    $("#myform").validate(); //apply the validation plugin to your form

	$("#username").rules("add", {
		 remote: {
			url: "check_username.php", //place the PHP here
			type: "post", //using the post method to send data (you may also use the get method)
				data: {
				  username: function() {
					return $("#username").val(); //get the value from the text input
				  }
				}
			},
		 messages: {
		   remote: "Username already taken. Please try a different username." //set the message you want to display
		 }
	});

});

The next step is to create the PHP page that checks if the user existed.  Because the validation only works with Boolean values,  so you will need to code the page to return the text true if username doesn’t exist or false otherwise.  Here is the search Query in PHP for this example.

$query="SELECT * FROM users WHERE LOWER(username) = '$username'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
//check if number of users with the username exist more than 0
if($num >0){
echo "false";
}else{
echo "true";
}

Test the form by typing any username that has already existed, your form should be showing an error message next to the username input as shown in the demo below.

Click here to view live demo

Get the complete source file: Ajax Form Example (99)

  • Share/Bookmark

My Boys, Best shots of 09′

Posted December 25th, 2009 in Personal Ramblings, Photography, Portfolio by Jimi Sulaiman

They grow up so fast :) ! These are shots taken between November to December this year.  Taken using 50mm lens f/1.4 on a Nikon D5000 body (mostly wide opened).  Post editing using Lightroom 2.

You can download the Lightroom2 presets available at the bottom of this post.

Download Lightroom 2 Presets used for the above images here: JS_LR_Presets.zip (71)

  • Share/Bookmark
Page 2 of 141234510...Last »