Tag Archives: function

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

By | March 1, 2011

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 :… Read More »

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

By | February 27, 2011

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.

How to detect shake Gesture in your iPhone Cocos2D?

By | February 26, 2011

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… Read More »

Hide and Show a Text Using jQuery – Example

By | February 26, 2011

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…. <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#hideButton").click(function(){ $("p").hide(); }); $("#showButton").click(function(){ $("p").show(); }); }); </script> </head> <body> <p>Hey!… Read More »

Preventing Overriding in Java

By | February 25, 2011

Methods and variables can be ‘override’ in subclasses. (Yes, it’s a good feature too!). But what if we don’t want to ‘override’ our Methods and Variables in Java? It’s simple… Declare them using the keyword ‘final’ as modifier. That’s it. eg: So the value of myVariable can never be changed any way. Also for Classes/Methods.… Read More »

Create PopUp Window in Adobe AIR / FLEX, A simple Example.

By | February 23, 2011

Below code shows how to create a new popUp window in Adobe AIR or FLEX. To create a new window “right click on the src folder and create a new MXML Component named Here “MyLoginForm” It should be aTitleWindow for the example below. How ever You can create other components, but the code accordingly must… Read More »

FullScreen Event in Adobe AIR or FLEX

By | February 22, 2011

  The following simple code snippet explains how to get an eventListener for FullScreen Event in Adobe AIR or FLEX. The function “onScreenModeChange ” gets called when you maximizes your window. private function init():void { stage.addEventListener( FullScreenEvent.FULL_SCREEN, onEnteringFullScreenMode); } private function onEnteringFullScreenMode( e:FullScreenEvent ):void { if( e.fullScreen ) { // Do something on fullscreen…………… } else… Read More »

How to remove unwanted frames from memory in iPhone?

By | February 13, 2011

In Cocos2D in iPhone often you may be using spritesheets which amy cause memory leaks because they are unused textures in memory even when you go from one scene to other. So make sure to remove all those unwanted textures from memory to save memory. Copy this following code to dealloc function in your class… Read More »

Play all songs from your raw directory in ANDROID continuously.

By | February 10, 2011

In ANDROID all resource has a unique resource ID which we get by passing the song name to the function below playSong(). The function getAllResourceIDs() will convert this String which is the name of the song to the unique resource ID which can then be used to play the song. setOnCompletionListener() will be executed when… Read More »

Trim() function in ActionScript(Adobe AIR , FLEX etc)…

By | February 9, 2011

The function for trim in ActionScript is defined inside StringUtil Class. Checkout the following function. public function stringTrim(result:String):String{ result = StringUtil.trim(result); trace(result); return result; } Please post your valuable comments if the post was useful. The function for trim in ActionScript is defined inside StringUtil Class. Checkout the following function. public function stringTrim(result:String):String{ result =… Read More »

Access a remote database from Adobe AIR or FLEX.

By | February 8, 2011

Access a remote database from Adobe AIR or FLEX. Many often you need to access online database from your application. For doing it in Adobe AIR of FLEX you need HttpService. The following example shows how to access an online database from an AIR Application. Note that you cannot return an array from a remote… Read More »

Crop an Image in Adobe AIR or Flex.

By | February 7, 2011

Below code shows how to crop an image in Adobe AIR. Change the mx:WindowedApplication to mx: Application to run it as a FLEX Application. The code uses copyPixels to extract the desired part from the image file. The important line in the below code crops the image. cropBD.copyPixels(loadBD, new Rectangle(startPoint.x, startPoint.y, squareSize, squareSize),posPoint);

Dynamically change the background of a window in Adobe AIR?

By | February 6, 2011

Change the background of your window with your selected image. Copy and paste the following code to your AIR file and view the result. Note: Please make sure that you have an image in your application source folder. Here the image name is “image.jpg” else you will get URL not found error.

Pass a variable from one window to another in Adobe AIR?

By | February 6, 2011

We often need to access another window variable in the current window. The following example shows how to access a variable from one window in the next window. The logic is to create an object of next window in the current window and assign the value of variable in the current window itself so that… Read More »

Create a polygon in Flash or Adobe AIR using Box2D.

By | February 5, 2011

The below function creates a polygon in the shape of a triangle. Please call the debugdraw function inside your update method to view the results. Make sure you import the Box2D classes into your file. public function init():void { debug_draw(); addEventListener(Event.ENTER_FRAME, update); createTriangle(); } public function createTriangle():void { var fd : b2FixtureDef = new b2FixtureDef();… Read More »

How to Implement Box2D in Adobe AIR?

By | February 4, 2011

Everyone will be fascinated how flash games are built on the web that implements the real world physics. Well for your information there are a lot of physics engines available. One of them is the Box2D. Box2D was written in C++. Then it was converted to flash. So now I am going to show you… Read More »

How to rotate a body manually in Box2D?

By | January 24, 2011

The below code helps you to rotate a body in Box2D manually. Here the body is named “rotating_body” which is going to rotate and a sprite named “rot_sprite” is it’s userData, please give your own image for it. Make sure that you have it in your resources otherwise your program will crash. Note: call this… Read More »

How to read and write an XML file in Adobe AIR or Flex?

By | January 15, 2011

AIR treats the XML files as just as normal file and so you can proceed using the FileStream classs. Please take a look at the sample code. Just copy and paste the following code to your main.MXML file and you are done. Please post your comments on this post

Add Context menu in Adobe AIR or FLEX.

By | January 15, 2011

This sample shows how to add a menu to your context menu or the right click of your menu in Adobe AIR. AIR Uses the ContextMenu class to add menu to your mouse right click. import flash.events.ContextMenuEvent; import mx.controls.Alert; // call this function to create context menu in AIR and FLex private function createContextMenu():void {… Read More »