First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
Search tutorials
Author: Martin Overmars | Website: http://www.56k.nl/

Step 3: Using the XML with ActionScript

Basic stuff: placing your FLV on stage

-File -> New... (CTRL+N) -> Flash Document (so, just what you would do normally) -> Ok.

-Click on frame1 on layer1 to select it.
-Window -> Components (CTRL+F7) -> FLV Playback - Player 8 -> FlvPlayback -> doubleclick -> you can exit the components window if you please.
-Leftclick on the component.
-Activate the parameters tab.
-Change the 'contentPath' to the location of your flv. Make sure the 'Match source file dimensions' box is checked.
-Change the 'skin' to 'none' or what you prefer.

-Activate the Properties Tab.
-Modify -> Document... (CTRL+J) -> change the default demensions: W(idth) and H(eight) to the values inside the properties window. -> Change the Frame Rate to the same of your movie, ex. 25 fps -> Ok
-Change both the X and the Y in the properties tab to 0.

Scripting

-Select frame1 on layer1.
-Window -> Actions (F9) -> paste alle script
//create an empty var, ready for XML content.
var xmlContent:XML = new XML();
//ignore empty elements like  instead of
//formatting them to  etc.
xmlContent.ignoreWhite = true;
//the first frame is the first frame where the movie starts playing..
//so start with index 0
i = 0;
//every frame in the flash file is a frame of the flv movie because we synched those
//so we can change the cooords of the animation in refference
//to the coords in the xml file each time the flash file enters a new frame
onEnterFrame = function () {
	//The flv might be playing before the xml is loaded but shit happens
	if (xmlIsLoaded == true) {
		//if the animation is out of synch with the flv..
		offset = -Math.round(25/2);
		//assign the framenumber to a variable
		newNumber = xmlContent.firstChild.childNodes[3].firstChild.childNodes[i+offset].childNodes[0].firstChild.firstChild.nodeValue;
		//assign the new x cooord to a variable
		newX = xmlContent.firstChild.childNodes[3].firstChild.childNodes[i+offset].childNodes[1].firstChild.firstChild.nodeValue;
		//assign the new y cooord to a variable
		newY = xmlContent.firstChild.childNodes[3].firstChild.childNodes[i+offset].childNodes[2].firstChild.firstChild.nodeValue;
		//if there are still framenumbers in the xml file then actualy give the movieClip it's new position
		if (newNumber != undefined) {
			theMovingObject._x = newX;
			theMovingObject._y = newY;
			//Track(newNumber+","+newX+","+newY);
		}
	}
	//Increment the number with one for each time a frame is entered.
	i++;
};
//If the xml file is loaded into flash then...
xmlContent.onLoad = function(loooaded:Boolean) {
	if (xmlContent.hasChildNodes()) {
		//Only start doing things with the xml when it's loaded already,
		//else we're only going to get a big pile of nonesence and maybe bugs.
		xmlIsLoaded = true;
		
		//As you might have seen or not, there is a pile of useless thingies
		//in the xml file, so when the xml is loaded
		//get rid of the useless elements in it.
		xmlContent.firstChild.childNodes[3].firstChild.firstChild.removeNode();
		xmlContent.firstChild.childNodes[3].firstChild.firstChild.removeNode();
		xmlContent.firstChild.childNodes[3].firstChild.firstChild.removeNode();
		xmlContent.firstChild.childNodes[3].firstChild.firstChild.removeNode();
		xmlContent.firstChild.childNodes[3].firstChild.firstChild.removeNode();
		xmlContent.firstChild.childNodes[3].firstChild.firstChild.removeNode();
		xmlContent.firstChild.childNodes[3].firstChild.firstChild.removeNode();
		xmlContent.firstChild.childNodes[3].firstChild.firstChild.removeNode();
		xmlContent.firstChild.childNodes[3].firstChild.lastChild.removeNode();
		xmlContent.firstChild.childNodes[3].firstChild.lastChild.removeNode();
		xmlContent.firstChild.childNodes[3].firstChild.lastChild.removeNode();
		xmlContent.firstChild.childNodes[3].firstChild.lastChild.removeNode();
	} else {
		//If the file is unreadable, then let me know
		//there is a big chance that you missed my note earlier in my tutorial
		//about that new-versions-of-excel xml thingy.
		Track("XML loading-errorblah");
	}
};
//Start loading the xml file wherein we'd put all
//coordinates and stuff from After Effects
xmlContent.load("07positions.xml");
-Create a movieclip called 'theMovingObject' with your object in it. Like the icecube or the helmet with the propellor on it in the examples I brought up earlier.
-Insert -> New symbol(CTRL+F8) -> make it available for actionscript.

-Make sure it also has the instance name 'theMovingObject'.

And that's it! Sort of... =) hope it was of 'some' use.

Martin
» Level Intermediate

Added: 2007-05-02
Rating: 10 Votes: 2
(10 being the highest)
» Author
Digital Media Design Student
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: S.Saipriya
» Title: Flash Fire Effect
» Description: This tutorial explains about how to create Fire Effect in Flash of Actionscript 2.0.I hope this tutorial helps you!
Featured Sound Loops
Image for equalize

Audio Player

» Author: Aidan Crouzet-Pascal
» Title: Falling Star
» Description: This loop is a cool sounding, E minor loop.
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Brandan Paulin
» Description: Epic sounding loop with Brass, Percussion, Strings and Winds. This is actually part of a Loop Pack called the Coming where you can download the rest of the loops that go with it FREE from my website.