Tutorial Actionscript 3 – How To Google Maps API

July 19th, 2009 miguelMoraleda 3 comments

The Google Maps API lets you embed Google Maps in your own web pages with JavaScript. The API provides a number of utilities for manipulating maps (just like on the http://maps.google.com web page) and adding content to the map through a variety of services, allowing you to create robust maps applications on your website.

In this post I will explain how to use the Google Maps API.

1.- The first thing that you need is to get your API KEY
Go to http://code.google.com/apis/maps/signup.html

After read and accept the terms and conditions and give your domain name. You will get your key.

googleMaps

2.- The next step is download the library kit of google maps for actionscript and flex.
To download the kit CLICK HERE
The kit contains 2 .swc files with the library.

3.- With the key and api we are ready to start with the code. Create a new project and config the library path to read the swc file downloaded. In your Flash IDE press edit-preferences-actionscript- actionscript 3 and add the folder with your swc files.

4.- THE CODE.

var _map:Map = new Map();
_map.key = "ACA DEBEN PONER SU KEY";
_map.language = "es";
_map.setSize(new Point(stage.stageWidth, stage.stageHeight));
_map.addEventListener(MapEvent.MAP_READY, onMapReady);
_map.y = 50;
addChild(_map);
 
function onMapReady(event:Event):void {
	_map.setCenter(new LatLng(40.736072, -73.992062), 14, MapType.NORMAL_MAP_TYPE);
}

With this simple code we have our example working.

googleMaps

I hope this post help you to understand how works the google maps API. Any question or suggestions are welcome

VIEW EXAMPLE
DOWNLOAD EXAMPLE



Categories: Actionscript 3, Flash Tags:

Tutorial actionscript3 – Loading sound and play as loop

July 10th, 2009 miguelMoraleda 2 comments

DOWNLOAD EXAMPLE

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.net.URLRequest;
 
	/**
	 * This class load a sound and play it in loop.
	 * @author http://www.miguelmoraleda.com
	 */
	public class Main extends Sprite
	{
		private var soundFactory:Sound;
		private var song:SoundChannel;
 
		public function Main()
		{
			super();
 
			loadSound("sound.mp3");
		}
 
		/**
		 * Load the sound
		 * @param	url
		 */
		private function loadSound(url:String):void
		{
			var request:URLRequest = new URLRequest(url);
            soundFactory = new Sound();
            soundFactory.addEventListener(Event.COMPLETE, completeHandler);
            soundFactory.load(request);
		}
 
		/**
		 * When sound is loaded, play it.
		 * @param	e
		 */
		private function completeHandler(e:Event):void
		{
			soundFactory.removeEventListener(Event.COMPLETE, completeHandler);
			playSound();
		}
 
		/**
		 * Play the sound and add listener to sound complete.
		 */
		private function playSound():void
		{
            song = soundFactory.play();
			song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
		}
 
		/**
		 * when the sound is finish play again.
		 * @param	e
		 */
		private function soundCompleteHandler(e:Event):void
		{
			song.removeEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
			playSound();
		}
	}
}



Categories: Actionscript 3, Flash Tags:

Augmented Reality – levelHead v1.0, 3-cube speedrun

May 23rd, 2009 miguelMoraleda 1 comment

Read more about the project here:
http://julianoliver.com/levelhead

Categories: Actionscript 3, Flash Tags:

Unity3D Game Development Tool – Example

May 13th, 2009 miguelMoraleda 3 comments

Unity3D is a multiplatform game development tool, designed from the start to ease creation. A fully integrated professional application, Unity just happens to contain the most powerful engine this side of a million dollars.

I was working with unity, and this is the result. A free style course for drive a hummer. You can change the camera view using the number from 1 to 3 and drive the car with the rows of the keyboard


VIEW EXAMPLE

hummer
hummer2


Categories: Unity3D Tags:

Tutorial JigLibFlash – How to create basic physics 3d scene.

April 24th, 2009 miguelMoraleda 10 comments


Introduction



Jiglibflash is a open source 3D physics engine. Official Web.
In this tutorial we will create a simple scene with some cubes and spheres. Those object will simulate physics.
The first thing we need is to create a basic 3d scene. JigLibFlash actually support Papervision3D, Away3D and Sandy3D. For this tutorial I will be using Papervision3d.


Lets begin



To create our scene we need a viewport, camera, render engine and scene. All this things are implemented in the BasicView class, for these reason our main class will extends from there. To get more information about it, read the next post by Andy Zupko BasicView – Making Life In Papervision a Little Easier

Our class at this moment.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package
{
	import flash.events.Event;
	import org.papervision3d.view.BasicView;
 
	public class Main extends BasicView
	{
		public function Main()
		{
			super(0, 0, true);
			startRendering();
		}
 
		override protected function onRenderTick(event:Event = null):void
		{
			super.onRenderTick(event);
		}
	}
}

If you compile the code now, you won’t see anything, but internally we have all neccesary things to render 3d objects. With this base we can start with the physics. In JigLibFlash you will find the Papervision3DPhysics class, it is a plugin to handle easier the engine and also have some functions to create objects.

For our example we need to add a new instance of Papervision3DPhysics in the main class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package
{
	import flash.events.Event;
	import jiglib.plugin.papervision3d.Papervision3DPhysics;
	import org.papervision3d.view.BasicView;
 
	public class Main extends BasicView
	{
 
		private var _physics:Papervision3DPhysics;
 
		public function Main()
		{
			super(0, 0, true);
 
			initPhysics();
			startRendering();
		}
 
		private function initPhysics():void
		{
                         //need the scene instance (Scene3D) and the speed for the engine
			_physics = new Papervision3DPhysics(scene, 7);
		}
 
		override protected function onRenderTick(event:Event = null):void
		{
                        //update the engine in each frame
			_physics.step();
			super.onRenderTick(event);
		}
	}
}

Now we have the scene ready to add objects. Again Papervision3DPhysics is a very helpful class, because it has some functions to create basic objects like Grounds, Cubes or Spheres.

How To create objects


Create Ground


1
2
3
4
5
private function createGround():void
{
	var mat:WireframeMaterial = new WireframeMaterial(0xCCCCCC);
	var ground:RigidBody = _physics.createGround(mat, 1000, 0);
}

Create Cube


1
2
3
4
5
6
private function createBox():void
{
	var materials:MaterialsList = new MaterialsList();
	materials.addMaterial(new WireframeMaterial(0xFF4444), "all");
	var box:RigidBody = _physics.createCube(materials, 100, 100, 100, 3, 3, 3);
}


Create Sphere


1
2
3
4
private function createSphere():void
{
	var ball:RigidBody = _physics.createSphere(new WireframeMaterial(0xFF44FF), 50);
}

These are the functions that you can use with Papervision3DPhysics. Don’t forget that Papervision3DPhysics is a class to get things easier and faster.
I hope this tutorial results helpful for you and motivates you to learn more about JigLib. Any suggests will be great.

VIEW EXAMPLE
DOWNLOAD TUTORIAL FILES



Categories: JigLibFlash Tags:

Google Realese O3D – open-source web API for creating interactive 3D applications in the browser

April 24th, 2009 miguelMoraleda No comments

O3D is an open-source web API for creating rich, interactive 3D applications in the browser. This API is shared at an early stage as part of a conversation with the broader developer community about establishing an open web standard for 3D graphics.

Google Code Page


Categories: etc Tags:

Tutorial actionscript 3 – How to read and save file in Adobe Air

April 22nd, 2009 miguelMoraleda 1 comment

This is a very simple example of how to read and save files with Air.

DOWNLOAD EXAMPLE

Categories: Air, Flash Tags:

Tutorial Actionscript 3 – How to use a webcam on Flash

April 18th, 2009 miguelMoraleda 5 comments

Use the webcam in flash is very easy. You need a Video instance and Camera instance.

1
2
3
4
5
6
7
8
9
10
//Create a video instance
video = new Video(640, 480);
//Get the camera reference.
camara = Camera.getCamera();
//setMode need 3 params, width, height and frame rate.
//Optianally you can set a boolean value at the end for the 	favorArea.
camara.setMode(640, 480, 30);
//put the camera in the video instance
video.attachCamera(camara);
addChild(video);

VIEW EXAMPLE
DOWNLOAD EXAMPLE


Categories: Actionscript 3, Flash Tags:

Facebook game – Football Soccer Challenge

April 9th, 2009 miguelMoraleda 1 comment

footballsoccerchallenge
This game is a personal project. It is about trying to keep a soccer ball in the air by clicking on it. Have a bonus system that do more difficult the game. The game works on Facebook, and you can see your friends ranking or the world ranking.

You could check the game on:
http://apps.facebook.com/footballsoccer/

Your feedback, will be very helpful.



Categories: Flash, Games Tags:

Actionscript 3 – Papervision3D Interactive Collada, DAE objects.

March 30th, 2009 miguelMoraleda 5 comments

If you dont know what is a collada object. The Collada files, are 3d models exported to xml format. With Papervision3D we can create the models into our flash. If you need more info you could read the next link

Collada Files in wikipedia

If you need interactive collada, must meet the following requirements:

  • Thw viewport must be interactive…. viewport.interactive = true.
  • All materials of the DAE object must be interactive also.
  • You need to add a listener for the InteractiveScene3DEvent that you want into each child of your collada.

Here a example how to set all materials to interactive :

1
2
3
4
5
6
7
private function setInteractiveMaterials(targetObject:DisplayObject3D, value:Boolean):void
{
	for each(var mat:MaterialObject3D in _targetObject.materials.materialsByName)
	{
		mat.interactive = value;
	}
}

How to put a eventListener into each child.

1
2
3
4
5
6
7
8
private function addEventListeners(displayObject:DisplayObject3D, eventType:String, listener:Function):void
{
	displayObject.addEventListener(eventType, listener);
 
	for each(var child:DisplayObject3D in displayObject.children) {
		addEventListeners(child, eventType, listener);
	}
}

The call of the last function will be this:

1
addEventListeners(_obj, InteractiveScene3DEvent.OBJECT_PRESS, daePressedHandler);

I’m not sure if this way is the better. If you have some idea or suggest please post your comments.

VIEW EXAMPLE
DOWNLOAD EXAMPLE FOR CS4
DOWNLOAD EXAMPLE FOR CS3



Categories: Papervision3d Tags:
Get Adobe Flash playerPlugin by wpburn.com wordpress themes