Remove unwanted memory from iPhone….

Hi all ……
You know iPhone doesnot have garbage collection like ANDROID. So it becomes the responsibility of the developer or programmer to release the resources and remove the unwanted textures from your memory.
If you don’t remove the unused textures and other variables from your memory your application will exit after a while.

You often have the problem that your iPhone application exits unexpectedly, Most probably this may be the reason.

One method to check is…….
1. Release variables declared inside a function from there itself.
2. Release other variables inside the dealloc() function.
3. Remove the textures that remain in memory when you use images.
4. If you are using particle effects then don’t use the particle release function.
5. Unload the sounds on dealloc.

For removing the variables you can use..

[my_var release];

For removing the textures from the memory use this code inside the dellaoc function.
Check out the console if it is working. It will show console outputs such as “removing unused texture bla bla bla..”

/** this will remove all the unused frames if you are using sprite sheets **/
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
/** this will remove unused textures of images if you are using only images **/
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
/** this will remove all textures from memory **/
[[CCTextureCache sharedTextureCache] removeAllTextures];

But still your program may exit. This is due to the second line and put only the this line..

[[CCTextureCache sharedTextureCache] removeUnusedTextures];

This may solve your problem…….
This above code will release most of your unused memory.

Please leave your valuable comments if this post was useful…..

Collision Detection In Box2D – Using With Cocos2D

For an interactive game building using Box2D, collision detection of Box2D bodies is necessary. There is an easy way to implement collision detection in Box2D.

For checking whether two bodies have collided with each other in Box2D while using it with cocos2D, then use the following lines of code where ever you want to check collision.

if((contact.fixtureA == sourceFixture && contact.fixtureB == destinationFixture) ||
(contact.fixtureA == destinationFixture && contact.fixtureB == sourceFixture ))
//What you want to do after checking the collision?!!!
//That lines of code goes here!
//Simple and Pretty , isn't it?

Here you are cheking whether two box2D fixtures are in contact or not! And you can decide which fixtures you need to check for collision.

Removing Forces From Your World in Box2D Cocos2D


In certain situations you may need to remove all the forces you have applied on different bodies in your box2D world.
Then what to do?
Removing all the forces from the bodies in the box2D world is simple. Just use the single line of code.


Here yourWorld is your Box2D world. Simple, isn’t it?

File Operations in Adobe AIR/FLEX

The following example shows how to deal with a simple text file in Adobe AIR/FLEX.
This example illustratesd how to write a string to a text file and save it in the desktop.
However you can use the “application directory” but make sure that you have necessary write permission to access the directory.


Please leave your valuable comments…..

How to turnOff suggestions in editText in ANDROID?

Sometimes we may not need suggestions to appear in the textbox in our application in ANDROID.
This simple codes turns off this suggestion ….
Put this code inside your editText tag in the layout xml file.


if the above code is not working try this…


Please leave your valuable comments………..

Creating a JMenubar in java swing

Creating a JMenubar is simple.

        JMenuBar  menubar = new JMenuBar();
	JMenu menu1 = new JMenu("File");
	JMenu menu2= new JMenu("Help");
	file = new JMenuItem("Exit to menu");
	edit = new JMenuItem("Exit");

	JMenuItem about = new JMenuItem("About us");

	file.addActionListener(new ActionListener()
		public void actionPerformed(ActionEvent arg0)
	edit.addActionListener(new ActionListener()
		public void actionPerformed(ActionEvent arg0)
	about.addActionListener(new ActionListener()
		public void actionPerformed(ActionEvent arg0)

Unscheduling All Selector Functions in Cocos2D iPhone

There may arise certain situations there you are using a number of @selector functions and want to stop all those selectors. In cocos2D there is an easy way to stop/unschedule all the selectors with a single line of code!

Use this line of code where ever you want to unshedule all the selectors being activated.

[self unscheduleAllSelectors];


Play an MP3 in Adobe AIR/FLEX

Often in out applications we need to play sounds , so this code explains how to play, stop and resume an mp3 sound in Adobe AIR/FLEX.
What you have to do is to copy the following code and place it inside your “mx:Script” tag.
After that place three buttons for play, pause and stop and connect it to the three functions coded below.
Make sure that you have the sound file in your applications directory.

import adobe.utils.CustomActions;

var sound:Sound = new Sound(new URLRequest("app:/my_sound.mp3"));
var my_channel:SoundChannel;
var pausePos:int = 0;
private function play():void
private function stop():void
      pausePosition = my_channel.position;
private function resume():void
       my_channel =;

Please leave your valuable comments.

How to load a PDF in Titanium?

Loading a PDF file in Titanium may be sometimes our requirement for an application. For loading a PDF we need to have a webview inside a scrollview so that it is scrollable also. Take a look at this simple example.

/** creating a window **/
var window = Titanium.UI.createWindow{};
/** creating a webview **/
var my_webview = Titanium.UI.createWebView({     url :'my_pdf.pdf'      //specify the PDF path.....});
/** creating a scrollview **/var my_scrollView = Titanium.UI.createScrollableView({     views:[my_webview]   // placing the webview inside the scrollview...});

Please leave your valuable comments if this post was useful…..

Load a webpage in Adobe AIR

This example shows how to load a webpage inside Adobe AIR,
For this first you have to place an HTML control in your design for loading the html content.
Create an page “index.html” inside the application directory of your current project and add some Html content to it.
After that copy the following code to your source file.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="" layout="absolute" applicationComplete="init()">
      private function init():void
         this.stage.nativeWindow.maximize();    // maximizes your window.
         html.location="index.html";            // loads the html content in the html text area.
<mx:HTML id="html"     width="100%" height="100%" />

Please leave your comments on this post…….

Dynamically Load CSS in Adobe AIR/FLEX / Load css in Adobe AIR/FLEX using Class.

This example shows how to dynamically load css in Adobe AIR / FLEX.
Here in this example Panel id the tag name for the panel control. Drag a panel control to your design then copy the code to your source file. “myTabs” is the class for the CSS.

	Panel {
   borderColor:  #CBE0FF;
   borderThickness: 1;
   borderThicknessLeft: 0;
   borderThicknessTop: 0;
   borderThicknessBottom: 0;
   borderThicknessRight: 0;
   cornerRadius: 4;
   highlightAlphas: 1, 0.49;
   headerColors: #0066ff, #ffffff;
   backgroundColor: #F5FAFF;
   borderThickness: 1;
   borderThicknessLeft: 0;
   borderThicknessTop: 0;
   borderThicknessBottom: 0;
   borderThicknessRight: 0;
   cornerRadius: 4;
   backgroundAlpha: 1;
   highlightAlphas: 1, 0.49;
   headerColors: #0066ff, #ffffff;
   backgroundColor: #F5FAFF;
   footerColors: #0099ff, #ffffff;

	cornerRadius: 4;
  	highlightAlphas: 0.52, 0.52;
	fillAlphas: 0, 1, 1, 1;
	fillColors: #0066ff, #ffffff, #ff9900, #eeeeee;
	borderColor: #cccccc;

ApplicationControlBar {
   highlightAlphas: 1, 0.42;
   fillAlphas: 0.78, 0.8;
   fillColors: #619ffc, #ffffff;
   backgroundAlpha: 1;
   cornerRadius: 1;
   shadowDistance: 1;
TabBar {
	tab-style-name: "myTabs";
	selected-tab-text-style-name: "mySelectedTabs";
.myTabs {
   cornerRadius: 4;
   highlightAlphas: 0.30, 0;
   fillAlphas: 0.60, 0.40;
   /* fillColors: #c0dcf9, #e8f0f8; */
   fillColors: #95d0fe, #95d0fe;
   borderColor: #ffffff;
   color: #0b333c;
   fontFamily: Arial;
   backgroundColor: #f8d49d;


.mySelectedTabs {
   textAlign: left;
   fontFamily: Arial;
   fontWeight: normal;
 backgroundColor: #ffffff;


Client Side Form Validation – using JavaScript

Hi, JavaScript is mainly used for client side scripting. In client side scripting one of the thing which we are usually in need is Validation of Forms. We want to know the user , who is interacting with the form have already given the necessary details before submitting or saving etc. Here is a simple form validation example using JavaScript where the form is checked for a particular text field have entered or not. Here is the form code

First name:

It contains a Text field to enter first name and a button to save.
On clicking the Save button it will go for ‘validateForm()’ function and checks for user entry.

validateForm() code

function validateForm()
var x=document.forms["trialForm"]["firstName"].value
if (x==null || x=="")
  alert("Enter your first name before saving!");
  return false;

This function checks for it & returns alert if it is not filled properly! :)

Using ButtonBar in Adobe AIR/FLEX, A simple Example


A button Bar is a convenient way to place your buttons in an application. It saves a lots of space in your application interface.
Take a look at the following example which shows how to use the ButtonBar. An itemClickEvent is attached to each button in the ButtonBar.
You can place as many buttons inside a button Bar.
Copy the following code to your MXML file and you are done…….
Happy Coding………..

<?xml version="1.0"?>
<mx:WindowedApplication xmlns:mx="" >

            private function clickHandler(event:ItemClickEvent):void {
                    myTA.text="Selected button index: " +
                    String(event.index) + "n" +
                    "Selected button label: " +

    <mx:ToggleButtonBar  borderStyle="solid"  horizontalGap="5"  itemClick="clickHandler(event);"
    	    toggleOnClick="true"  selectedIndex="-1">
    <mx:TextArea id="myTA" width="250" height="100"/>

Please leave your comments on this post.

How to load a URL in Objective C or Cocoa in iPhone?/ Open Safari in Objective C

This code snippet helps you to open a webpage in Safari.
Code uses openURL to load the webpage in the web browser.
Write this function as an action to a button………

- ( IBAction ) loadWebPageInSafari : ( id ) sender
          NSURL *my_URL = [NSURL URLWithString:[Your_URL stringValue]];
          if ( [ [NSWorkspace sharedWorkspace] openURL : my_URL ] ){
                   NSLog(@” URL Loaded................”);
                   NSLog(@" Failed to Load URL.....");

Using Arrays in JavaScript – Basics


We all know, Arrays are nothing but variables which can hold all your variable values with a single name.

Let’s see some basic operations of Arrays in JavaScript.

To Create a New Array. Use the following code.

 var myArray = new Array();

This code of line created a new Array object called myArray.

Adding Elements to myArray

myArray[0]= "you";
myArray[1] = "me";
myArray[2] = "we";


var myArray=new Array("you","me","we"); 


var myArray=["you","me","we"];

Accessing Array Elements


It will print ‘you’!

How to get a selected Item from a spinner in ANDROID?

We have come across this issue many times during programming to get a selected item in your combobox.
ANDROID has built in functions to get the selected item from a spinner.
Take a look at the snippet.
Here my_spinner id the spinner variable and using getSelectedItem() which will return an object and by using toString() I am converting it to human readable string…


Please leave your valuable comments…..

How to add more than One HTML Document in a single Browser ?


There may arise certain situations where you need to include more than one HTML document in the same browser.

But how?

It’s simple. It’s by using FRAMES of HTML.
FRAMES can be included inside FRAMESET.

Let’s see an example.

<frameset cols="200,400">
   <frame src="" />
   <frame src="" />

This will create two column frames in the browser with www.coderzheaven in one frame with 200 pixels, and in another frame with 400 pixel.

You can also give cols percentage as well. Like cols=”25%,75%”.

ProgressBar in ANDROID…..

Progress bars are our basic needs when we want to show something for a long time or some progress takes a long time and we want to show it’s progress.
Keeping that in mind ANDROID also has built in progress views.
There are basically two types of progress views in ANDROID.

ProgressDialog.STYLE_SPINNER and ProgressDialog.STYLE_HORIZONTAL

Take a look at this simple example that loads a progressBar on “onCreate”….

public class Example extends Activity
    protected void onCreate(Bundle savedInstanceState)
    	ProgressDialog dialog =, "", "Loading...", true);

Toggle between Full Screen and normal Screen in Adobe AIR or FLEX.

Hi all………

We often need to toggle between fullscreen and normal screen in our application.
The following code snippet helps you to toggle between these two screens in Adobe AIR or Flex.
Here I am using StageDisplayState class to do both which has “stage.displayState = StageDisplayState.FULL_SCREEN” and ” stage.displayState = StageDisplayState.NORMAL” constants to do this.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="" layout="absolute"  applicationComplete="toggleScreen()">
                       import flash.display.StageDisplayState;
                       private function toggleScreen():void{
                               if(fullScreen.selected == true){
                               } else {
                       private function goFullScreen():void {
                               stage.displayState = StageDisplayState.FULL_SCREEN;
                       private function exitFullScreen():void {
                               stage.displayState = StageDisplayState.NORMAL;
       <mx:CheckBox label="Full Screen" id="fullScreen" click="this.toggleScreen()"
               	               selected="true"  horizontalCenter="0" verticalCenter="0"/>

How to detect shake Gesture in your iPhone Cocos2D?

For detecting shake in a cocos2D program copy these lines to your layer class

bool shaked_once; //default false

self.isAccelerometerEnabled = YES;
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:1/60];
shaked_once = false;

Then copy this function to the same file…. and you are done……..

-(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

            float THRESHOLD = 2;

        if (acceleration.x > THRESHOLD || acceleration.x < -THRESHOLD ||
                          acceleration.y > THRESHOLD || acceleration.y < -THRESHOLD ||
                                      acceleration.z > THRESHOLD || acceleration.z < -THRESHOLD) {
                    if (!shaked_once) {
                           shaked_once = true;
         else {
                          shaked_once = false;

Hide and Show a Text Using jQuery – Example

With jQuery manipulation of HTML & CSS can be done very easily.
Here we are going to show how to Hide a line of text using jQuery & Show it back also.
Let’s code speak first….


<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">




<p>Hey! Click 'Left', I will vanish! Click 'Right', I will be back!</p>

<button id="hideButton">Left</button>
<button id="showButton">Right</button>

Note : Download and put ‘jquery.js’ on your working folder before trying out!

What these code did?

Here we have one line text, html paragraph. Two buttons ‘Left’ & ‘RIght’ and whose id’s

are ‘hideButton’ & ‘showButton’ respectively.

jQuery code identifies which button we clicked using the button id’s mentioned above and

apply the hide() or show() function to the html paragraph p.