Archive

Author Archive

Problem running CodeIgniter over goDaddy

March 17th, 2009

I have been getting “No input file specified” problem with the CodeIgniter based application. This issue has a quick fix.
There will be a php.ini file in the root directory. Copy it and rename the new file as php5.ini and just add following line in it:

cgi.fix_pathinfo = 1
//this directive tell PHP CGI to fix paths to conform to the spec

It solved my problem and CI application worked.

FYI: I have written codeIgniter advantages in another post at  zigron blog

Share/Save/Bookmark

Jawad Khan PHP, Uncategorized , , ,

Flash Percent Uploader with Symfony!

August 22nd, 2008

Flash Percent Uploader with Symfony!

I just had to upload 40+mb of video file sizes to one of my recent project, For this purpose using simple form is obviously not a good choice as user never knows how much data has been transferred and how much left. So percent uploader was inevitable here, for this purpose flash offers fileReference class which can be used to upload mutliple files to the server, with this filereference class you can get file size at onSelect event, so you can apply max-upload file size check and as well as you can monitor file transfer with onProgress event. The only problem while implementing the flash percent uploader is that you may recieve message like “A flash script is causing you computer to get slow! Would you like to abort it?”. The best way to avoid this error message is to make flash script busy in doing something else while uploading, it can be as simple as incrementing tmp variable.
Also, you will definitely love to increase upload limit at server, For PHP you will change the following variables:
upload_max_filesize = 50M
post_max_size = 50M

Now it was as simple as it is for the non-symfony apps, The problem of using this with symfony app is that upload() method of fileReference class cannot initiate an action of the symfony application. On calling the action it does nothing, It does not even gives HTTP error 404 or anything like that, means it founds the path to the action (note that upload method returns true), but the action cannot communicate with it. So to overcome this problem, we will write our upload script in a file under web directory and we can call that script directly from the upload() method. like:-
var item:FileReference = new FileReference();
path_to_upload_script = “……/uploader.php”;
item.upload(path_to_upload_script); // note that the parameter path should be absolute

Now you may require to do some database activity, may need to create some criteria and doSelects, wondering if thats possible from the script in the web directory? Then yes its possible, instead using:
sfContext::getInstance()->getController()->dispatch(); // that is used in index.php, we don’t need to dispatch the controller otherwise it will goto default homepage of our symfony app. We just need to get sfContext Instance. like:
sfContext::getInstance();

Now you are ready to go, you can call the script and can communicate with the database as well.

Share/Save/Bookmark

Jawad Khan Flash Actionscript, symfony , , , ,

Using Flash with Symfony!

July 21st, 2008

well being a flash developer and being a symfony developer feels really good :) .. Anyways, Symfony is awsome framework for developing today’s web-applications with its nice and fine MVC architecture. So symfony developers and flash developers should know how they will work together seamlessly.
First thing is to embed the flash into your template, we know that all the assets, graphics, javascripts, css etc belongs to the web folder of symfony’s project directory structure. So flash files will go here as well. I will recommend to create a folder named ‘flash’ .

to embed the flash in your template, you will use same <object> tag as done in the normal html files, but ofcourse you will give the relative or absolute url of your flash src, for this purpose we can use functions like _compute_public_path(…) in symfony. it will take flash file’s parameters, like its name, extension and folder. this function returns the path which will be used for the embed source.

Now we are done with embeding, and now we will focus on data communication b/w flash and symfony, guess what its even more easier..  The right way to communicate data is in xml format. e.g. if my flash movie requires usernames and birthdays for all the members of my site, I will create an action specifically for the flash component, let’s say executeGetBirthdays(), i will create the template against the action as well.. Now i will put the xml generation logic in my action and i will print the resultant xml in my templateSuccess.php. Now I want the template to not to display irrelevant header and other info and just needs to start with the xml document root tag, so that my flash component can easily parse it. Therefore, I will put following line in the action:
$this->setLayout(false);

Calling a symfony action from the flash is simple, just create an instance from the XML class..i.e
x1 = new XML();//xml class rather
x1.onLoad = function()
{
// xml parsing and rest of the stuff
}

x1.load(’getBirthDays’);

Share/Save/Bookmark

Jawad Khan Flash Actionscript, symfony , , , ,

Using sfCryptographp with custom validation

July 18th, 2008

Using sfCryptographp with custom validation..

I just had to use captcha with symfony, Symfony is a great MVC framework, but i really don’t like its default validation method, rather I like javascript validations, so that user don’t have to wait for the server response after missing just a text field. So, I put mostly fields checking validations with javascript and then check at the server for the specific fields which do require server response like checking username if its unique in the database. Such validations are also possible with the quick response using Ajax, but all we need to do is to avoid symfony’s default validation method in order to achieve that.

Now coming back to captcha, the php-captha is a great library for the normal php apps, It can also be used with symfony, but I gave preference to symfony’s already available pluggins..
so here is the pluggin: sfCryptographp
its installation is pretty straight forward.

$ symfony plugin-install http://plugins.symfony-project.com/sfCryptographpPlugin

After your done with installation, enable the crypt pluggin in your settings.yml file

like:

.settings:
enabled_modules:        [default, cryptographp]

Now, Open your template file, add following line:
<?php use_helper(’Cryptographp’); ?>

Now insert following code in anywhere within the form where you want captcha to be visible.

<?php echo cryptographp_picture(); ?>
<?php echo cryptographp_reload(); ?>

<?php echo input_tag(’captcha’); ?>

It was pretty easy, now if u test your template you can see captcha images, The above code lines are same as described in sfCryptographp wiki page. Now for the validation we will not follow the wiki, we will put some logic at the actions file. before we do it we need little modification in sfCryptographpValidator class, which can be found at:

plugins\sfCryptographpPlugin\lib\validator\sfCryptographpValidator.class.php

open that class

add another function like:

public function checkCode($value)
{
if (chk_crypt($value)) {
return true;
} else {
return false;
}

}

Now goto your actions class, put the following code at the place where you are handling form post actions.

// create an instance from sfCryptographpValidator class
// and use the new function to validate user entered text

$captcha = new sfCryptographpValidator();

if (!$captcha->checkCode($_POST['captcha']))
{
//user entered wrong code…
}

Share/Save/Bookmark

Jawad Khan PHP, symfony , ,

Loading / unloading youtube videos in flash

July 9th, 2008

Loading / unloading youtube videos in flash

Hi dear readers, I recently loaded youtube videos in a flash project, it was quite straight forward, but however there was a issue when unloading the videos, cz if you donot unload the movie, it will keep playing and its sound will keep coming out, despite the fact you transfer control to anywhere at the movie.

So, I searched the forums, but I could’nt found the solution. Lots of guys are facing this issue. So, here is the solution:

// The first thing to load any external MC,
// is to create an instance of movieclipLoader Class.

var video_mcl:MovieClipLoader = new MovieClipLoader();

// Now you will like to create a container where the MC will actually load.

this.createEmptyMovieClip(”container”,this.getNextHighestDepth());

// Create a listener object

var mclListener:Object = new Object();

// add it to the movieClipLoader object

video_mcl.addListener(mclListener);

// onLoadInit will be triggered when the external MC is ready. So its nice place to set new MC dimensions etc.

mclListener.onLoadInit = function(target_mc:MovieClip) {
// set dimensions or anything..

}

// now assign youtube’s movie id and create complete URL to load from.
utube_id = “UfMglbWyX4I”;
full_address = “http://www.youtube.com/v/” + utube_id;

//eventually use loadClip function
video_mcl.loadClip(full_address, container);

Now your youtube MC is loaded and its playing by default. Now you have to unload it or close it.

The first thing that will come to flash developer’s mind is  movieClipLoader’s class unloadClip function:-

i.e:

video_mcl.unloadClip(container); // but unfortunately that doesnot work to unload youtube’s MC.

Secondly, you can try removing the container MC which contains the loaded content
i.e:

container.removeMovieClip() // but unfortunately you cannot explicity remove the container MC.

so last but not the least, you will try to atleast stop the sound and will use global function, i.e:

stopAllSounds(); // but that will work for the FLASH IDE, but after publishing it wont hav any affect..

So here is the tip, when you load the youtube MC in your container, then your container reacts as a youtube player.. Infact its the youtube player now and you can control all of youtube’s api functions available with that container object..
So simply doing:

container.stopVideo(); // will stop the video and its sound.

you can use all other functions with the container instance as well..
Hope it helps to all who got stucked with this issue..
cheers
Jawad.

Share/Save/Bookmark

Jawad Khan Flash Actionscript , ,

Game development using Flash.

June 29th, 2008

Game development using Flash.

hi readers, am writing this blog entry for those flash developers who want to get their hands into flash game development. I will use AS2.0 syntax for the examples. When I have to learn something then code snippets really help. So I will keep writing those sample codes, you can copy / paste those in your Flash IDE and instantly experiment on them.
Basic Maths
First of all, we need to learn basic Maths, I will not go deep into mathematics, so here is the guideline for basic maths
-> Learning basic geometry and basic coordinate system.
-> Learning basic trignometry,Learning sines, cosines and tangents and learning how to apply them.
for instance, if you are given two points (x1, y1) and (x2,y2) on the plane, you should be able to findout the angle forming b/w those points w.r.t normal.

Differences b/w Flash and cartesian coordinate system:
we need to clear out few differences between standard rules and flash rules. We are aware of Cartesian coordinate system, in which x represents horizontal axis and y represents vertical axis and the center point is (x=0,y=0). But in flash the point (0,0) lies at the top left corner of the stage and contrary to cartesian coordinate system the value of y increases as we go down.
Getting position of the object:
We can retrieve and set the x and y values for any movieclip using movieclip’s class properties _x and _y.
for instance:
I can create a movieclip using createEmptyMovieClip method
var container:MovieClip = this.createEmptyMovieClip(”container”, this.getNextHighestDepth());
// then I create a textfield inside t he newly created movieclip.
var label:TextField = container.createTextField(”label”, 1, 0, 0, 150, 20);
label.text = “Hi boy”;

Now a movieclip ‘container’ has been created on the stage and now we can get its x and y values. By default it’s x and y values are 0,0. You can confirm this using famous trace command.
trace(container._x);
trace(container._y);
object movement and user interactivity
If you execute this code, you will see “hi boy” written at top left of the stage.
Now you can easily change these values as well. Moreover if u want your movieclip “hi boy” to constantly change its position, you can use event “enterframe” like following:
this.onEnterFrame=function()
{
container._x++;
if(container._x > 500)
{
container._x = 0;
}
}

This will keep movieclip container in a motion at x-axis. I put a condition cz it was neccessary otherwise container movieclip would have disappeared and left the stage for ever.
Now instead putting textfield in the container object you can draw any shape or object and move it.
In games, user interaction is must. You put user interactivity using various keyboard and mouse events. A simple key event can be used as follows:
if (Key.isDown(Key.RIGHT)) {
container._x++;
}
In the above example instead moving the object constantly, we are moving it whenever user presses ‘right’ arrow key.
Now it was the very basics of flash coordinates, object movements and user interactivity. stay tunned for the next releases.

Share/Save/Bookmark

Jawad Khan Flash Actionscript , , , , ,

Tips for Age of Empires II

May 21st, 2008

Hi,

I am writing this quick post to help my colleagues get more knowledge about AOE, cz we just changed our evening game session from MOHAA to AOE just for the change of taste. Also AOE is real time strategy game.

So here are the quick tips:-

1) First thing you need is to select your civilization, That is important step, and it takes time to understand that which civilization works out best against particular civilizations. few examples: If your enemy has GOTHS, and you select any civilization which has their stronger units as archers then it will not work against Goths as GOTHs special units has strong Armor against archers. other example can be that if you make up an army of paladins, huge army of paladins and your enemy has the civilization “Saracens” They will massacre your strong paladins within seconds with their special unit “Mamulakes”..

Each civlization’s stronger unit is produced from the castle. e.g. “Mongols” castle will produce their special unit a horse archer named as “Mangudai”.

The effectiveness of units against each other is realistic as it were during the earlier ages. e.g. If you got paladins and enemy makes pikemens which are relatively very cheap but very effective against mounted units, then eventually your loss will be more as compared to your enemy, keeping resources in mind.

2 ) Starting from the dark age, first thing you need to concentrate is to create more and more villagers, more villagers you build, more resources you will be able to gather and so utlimately more and powerful army you will be able to put up. So keep on making houses and keep on making villagers.

3 ) You need to keep checking the idle villages, put them at work. Each second is important.

4 ) Find out relics and capture them asap.

5 ) Keep doing important researches

6 ) Never make an army of a single unit.. Select your 3 or more fighting units.. Make them in numbers and do all relevant researches for that particular units.

7 ) You need to make lot of army buildings, stables, barracks, archery range, so incase your army is defeated, you can quickly re-make the backup.

8 ) During large battles, micro management is very essential, like a general during the real battles. If you make an army of 100 units and your enemy who got 10 units can finish off your army, if you put your army over your enemy without managing, your enemy’s siege weapons can destroy your army, unless you micro-manage your units to kill that siege weapons. You have to select a group of your army and keep killing high priority enemy units. don’t select all of your army for that particular task otherwise they all will be focusing one unit and will take losses from the surrounding enemy units. keep few of them fighting with their own AI.

9 ) If you are playing in a team then do make a market at your earliest and start trading, and yes don’t make one or two trade carts…. Make them in numbers!!… For 200 population limits, atleast make 15 trade carts.. They will give you enof gold that you don’t need to go and find goldmines.

10 ) Keep assisting your partner(s). cz If they die, your chances of survival will be very less. Infact continuously coordinate with each other. Plan the attacks together. Its all about team work.

Share/Save/Bookmark

Jawad Khan RTS Games , , ,