RE: idMap
RE: RE: idMap
Still the same, I tried your suggestion, and your website suggestion for the xml.as file, after that i started F8 again, but still the same, i tried everything, but no luck.....any suggestion?
Kees
If you’re anything like me, you don’t particularly enjoy having to launch Flash for a quick little fix, export again and deploy it on a website.
Well using the power of XML you can make your life a lot easier. What I’ll be discussing in this article is the concept of a configuration XML file and how to use it most efficiently for your Flash projects.
What exactly is a configuration XML file I hear you saying? It’s not difficult at all; in simple terms what it does is define some properties and corresponding values that overwrite the default values in your Flash application.
Let’s look at an example of such an XML file:
<config>
<param id="companyName" value="DMXzone" />
<param id="companyLink" value="http://www.dmxzone.com" />
</config>
The XML file above shows a typical configuration XML file that allows you to change the companyName and companyLink variables without having to recompile the Flash application.
This XML document is saved as config.xml and placed in the root folder of your Flash application. Of course that’s not enough to get it to work; we need a little bit of code in the Flash application to load in the XML and get hold of the configuration parameters which we’ll look at next.
Finally, to finish the application we'll look at the function that loads in the video and uses progressive download to play it in the video instance.
loadVideo = function() {
var vid_nc:NetConnection = new NetConnection();
vid_nc.connect(null);
var vid_ns:NetStream = new NetStream(vid_nc);
videoPlayer_vid.attachVideo(vid_ns);
vid_ns.play(getConfigParam("videoFile"));
}
The loadVideo function sets up a NetConnection and NetStream instance to progressively stream the FLV video file. Then to get the video playback started the videoPlayer_vid video instance on stage gets the NetStream instance attached and we again use the getConfigParam function to retrieve the videoFile variable.
One more line of code is needed to initialize the application:
loadConfig("config.xml");
If you now run the Flash application (Control > Test Movie), you'll see the following:
As expected the companyName and companyLink variables were taken from the configuration XML file. The video file which is playing is video1.flv which was defined as the default value in the FLA. Likewise if you click the title it will take you to http://www.dmxzone.com.
From this you can see that the code reverts back to the default value if that particular variable is not defined in the configuration XML file.
This is where it gets fun – by making some simple changes to the XML file we can quickly customize the application.
Let's update the config.xml file as follows:
<?xml version="1.0" ?>
<config>
<param id="companyName" value="DMXzone" />
<param id="companyLink" value="http://www.dmxzone.com" />
<param id="videoFile" value="video2.flv" />
</config>
What we did here was simply add one extra node that defines the videoFile variable and sets its value to video2.flv. The default value in the FLA is video1.flv, so if we run this Flash application it should play a different file without having to recompile anything.
Yes! Isn't that fun – we've now got the video player application running another video file. You're probably starting to see the potential of using the configuration XML technique now.
Let's think of some other possible uses. What about defining a color for the background panel, defining the font and title color, setting a variable that defines whether or not to loop the video playback? Those are all possible uses for the configuration XML file.
In all its simplicity this is one of those techniques I can't live without when doing Flash application development. I'd strongly recommend you give this a go for your next Flash application and see how it works for you.
Peter Elst is a Flash certified professional, Team Macromedia volunteer and runs his own company named MindStudio doing mostly freelance Flash and Flex consultancy, development and training. As a valued contributor to the online Flash community, Peter has presented at numerous international events and conferences and has had his work published in leading magazines and websites.
Over the years the focus of his work changed from interactive animations to multimedia applications, e-learning and content management systems. Peter is user group manager for the MMUG Belgium and blogs on his personal website: www.peterelst.com