IE179 Project 2

Flash Game Tutorial 3



In this tutorial you'll learn to use XML to describe your scene.

  1. Open a new flash document.
  2. Create a new movie clip symbol named platform that contains a rectangle.
  3. Open the library window and select the icon for the platform. Open the library window menu and select "Linkage." Export the symbol for actionScript.
  4. Return to the main stage.
  5. Create two layers name scripts and assets.
  6. Select the scripts layer and add the following code to the actionScript window.
    
    theLevel = new XML();
    theLevel.onLoad=parseLevel;
    theLevel.load("level.xml");
    var platforms = new Array();
    function parseLevel() {
    	trace("Read level description.");
    	var p=theLevel.childNodes[0];
    	for (var i=0;i < p.childNodes.length;++i) {
    		var x,y,w,h, clip;;
    		var theClip
    		x=Number(p.childNodes[i].attributes.x);
    		y=Number(p.childNodes[i].attributes.y);
    		w=Number(p.childNodes[i].attributes.width);
    		h=Number(p.childNodes[i].attributes.height);
    		clip=p.childNodes[i].attributes.clip;
    		clipName=clip+i
    		platforms[i] = new Platform(x,y,w,h,clip,clipName);
    		theClip = attachMovie(clip,clipName,0);
    		theClip._x = x;
    		theClip._y = y;
    		theClip._height = h;
    		theClip._width = w;
    	}
    }
    
    function Platform(x,y,width,height,clip,clipName) {
    	this.x = x;
    	this.y = y;
    	this.width = width;
    	this.height = height;
    	this.clip = clip;
    	this.name = clipName
    }
    
  7. Download the following file to the same folder as your new flash document.
  8. Test your game.