Archive

Posts Tagged ‘Actionscript’

Actionscript 3 Game – Space Invaders example, source code

March 8th, 2009 1 comment



space-invaders
This is a very precarious space invaders, which started while studying the book of design patterns “Actionscript 3.0 Design Patterns” by O’Reilly, specifically the chapter’s Factory Patern, started on this instance to mount the game (say something quite simple), was also working Mauricio Stkel, collegue. Well now I share with you what you want to see the code. The code in a project on google code, so there are for download the repository using a tool like svn version;), if someone comes to us not to mention better for the changes go in the same project. The project can continue whoever.

Here a example.
http://lab.miguelmoraleda.com/mongitime

Google Code:
http://code.google.com/p/mongitime/





Tutorial Actionscript 3 – create link button, listeners, addEventListener, events handlers

March 8th, 2009 5 comments



This post is for those who are starting with actionscript 3 and still do not understand very well the use of listeners. Explained very simply the listener are sensors that can add to objects. These sensors warn us call a function whenever a certain event occurs.

In AS2 we were able to directly tell to the instances:

myObj.onClick() {
 
}

and into this function write the behavior.

For Actionscript 3 you need to add a listener to the instance:

myObj.addEventListener(MouseEvent.CLICK, clickHandler);
 
function clickHandler(event:MouseEvent) {
  trace("myObj pressed");
}

Thus we can capture a multitude of events that long objects. Here a small list of the most common:

Event.ADDED_TO_STAGE
Event.COMPLETE
Event.ENTER_FRAME
Event.INIT
Event.CHANGE
Event.ACTIVATE
Event.ADDED
Event.CLOSE
Event.RESIZE
Event.SELECT

MouseEvent.CLICK
MouseEvent.MOUSE_DOWN
MouseEvent.MOUSE_UP
MouseEvent.MOUSE_MOVE
MouseEvent.MOUSE_OVER
MouseEvent.MOUSE_OUT
MouseEvent.ROLL_OVER
MouseEvent.ROLL_OUT

NOTE: Not all the objects dispatch all events.

This would be an example of how to open a page. Create a LINK:

graphicInstance.addEventListener(MouseEvent.CLICK, mouseClick);
 
  function mouseClick(e:MouseEvent) {
    var url:String = "http://www.miguelmoraleda.com";
    var request:URLRequest = new URLRequest(url);
    try {
        navigateToURL(request);
    }
    catch (e:Error) {
        // handle error here
    }
  }

 

Categories: Actionscript 3, Flash Tags:

Tutorial actionscript 3 – Load and read XML file, loading and reading

March 8th, 2009 1 comment



Reading a forum actionscript http://www.forosdelweb.com/f16/. I found repeated a post asking how to load XML. That motivates me to write the next post.

For those who know nothing about XML stands for Extensible Markup Language, to explain in a simple manner that most are not text files that follow certain standardizations to store data. The syntax rules we impose on xml, allows us to read these files from any language. I am not a scholar on the basic theory of the xml, just give them a good use in my programs. For those who want to study a bit more on xml can be read here. XML IN WIKIPEDIA

XML EXAMPLE:
xmlcode
As you can see the format is quite clever, using a format tag enclosing symbols between greater and less in the identifiers and values, who know html sure you get to fly.

Here a example of the usage. I will continue working on this example to see how to create a gallery of images with this xml.

VER EJEMPLO / VIEW EXAMPLE
DESCARGAR EJEMPLO / DOWNLOAD EXAMPLE

package
{
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
 
	/**
	 * This class is a little example of hot to work with xml files
	 * @author http://as3.miguelmoraleda.com
	 */
	public class Main extends Sprite
	{
 
		private var _xml:XML;
 
		public function Main()
		{
			super();
 
			loadXMLFile();
		}
 
		private function loadXMLFile():void
		{
			var loader= new URLLoader(new URLRequest("datos.xml"));
			loader.addEventListener(Event.COMPLETE, loadedCompleteHandler);
		}
 
		private function loadedCompleteHandler(e:Event):void
		{
			e.target.removeEventListener(Event.COMPLETE, loadedCompleteHandler);
			_xml = XML(e.target.data);
			for each (var picture:XML in _xml.pic) {
				statusField.text += "========================================\n";
				statusField.text += "Imagen: " + picture.image + "\n";
				statusField.text += "Nombre: " + picture.nombre + "\n";
				statusField.text += "Anio: " + picture.ano + "\n";
 
				trace("Imagen: " + picture.image);
				trace("Nombre: " + picture.nombre);
				trace("Anio: " + picture.ano);
			}
		}
	}
}
Categories: Actionscript 3 Tags:

Actionscript 3 MouseEvent MOUSE_OVER Vs ROLL_OVER, mouse over button

March 8th, 2009 1 comment

This is especially good for those who have the doubt which is the difference between these two events. I had so far. The thing is simple, roll identifies when the mouse enters and leaves on a resort, but if that many small childs body has within it, this event does not recognize those childs. On the other hand the event MOUSE_OVER and MOUSE_OUT difference if they do, these events accurately assess on this mouse, so it is dispatched each time the mouse switches between these childs. Clearly those who have read the forum will know that I’m not as for writing, so here I leave them an example and the code. (sorry google traslator i need to fix it)

DOWNLOAD EXAMPLE


Categories: Actionscript 3, Flash Tags:

Flash Actionscript 3 How to rotate object 360º degrees

March 8th, 2009 No comments

This is a very simple example of how to rotate an object 360 degrees. The theory is very simple, you must have a movieclip that contains a set of images with the rotation of any element. Then you can use a Slider component to go to  movieclip frame desired.

download example



Categories: Actionscript 3, Flash Tags:
Get Adobe Flash player