Instead of using "test_1.swf" or "test_2.jpg" in the <IMAGE> tags shown below, we are wanting to call a movieClip from the same library as the .FLA via XML.
Is this possible using XML and AS3?
< ?xml version="1.0" encoding="UTF-8"?>
< all>
< GROUP>
<IMAGE>test_1.swf</IMAGE>
<QUESTION>Question example #1</QUESTION>
<OPTION1>Option A example</OPTION1>
<OPTION2>Option B example/OPTION2>
<OPTION3>Option C example</OPTION3>
<IMAGE>test_2.jpg</IMAGE>
<QUESTION>Question example #2</QUESTION>
<OPTION1>Option A example</OPTION1>
<OPTION2>Option B example/OPTION2>
<OPTION3>Option C example</OPTION3>
< /GROUP>
< /all>
Just a note on complex projects with SWCs containing the clips you want to load. I've found I cannot getDefinitionByName() to dynamically find a class in a SWC unless the compiler knew about it ahead of time. This was a huge pain in the butt. The only tedious workaround I found was to declare an instance of that type in the Main document class of that library linkage type. From then on, any other classes no matter how deep could see that class via getDefinitionByName().
You didn't need to actually instantiate it, just mark a variable of that type. Otherwise the compiler does not compile that class properly and gDBN returns undefined. This is an annoying bug, really difficult to track down.. AAMOF I might open a bug request if I can reproduce this in the latest FP/AIR.
e.g. Main class Main.as:
package
{
public class Main
{
public function Main()
{
// uselessly pre-declare all linkage IDs I'll need later so the
// compiler will know they exist
_initRefs();
}
protected function _initRefs():void
{
// good enough, the compiler knows it must link this class from
// whatever SWC has it.. without this any other class can't find
// it via getDefinitionByName
var blah:SomeLinkageID;
}
}
}
data.xml:
< ?xml version="1.0" encoding="UTF-8"?>
< all>
< GROUP>
<IMAGE>MC1</IMAGE>
<QUESTION>Question example #1</QUESTION>
<OPTION1>Option A example</OPTION1>
<OPTION2>Option B example/OPTION2>
<OPTION3>Option C example</OPTION3>
<IMAGE>MC2</IMAGE>
<QUESTION>Question example #2</QUESTION>
<OPTION1>Option A example</OPTION1>
<OPTION2>Option B example/OPTION2>
<OPTION3>Option C example</OPTION3>
< /GROUP>
< /all>
// a.s.
var urlLoader:URLLoader=new URLLoader();
urlLoader.addEventListener(Event.COMPLETE,completeF);
urlLoader.load(new URLRequest("data.xml"));
function completeF(e:Event):void{
var xml:XML=XML(e.data);
var instance:*=stringToClassInstanceF(xml.GROUP.IMAGE[0]);
addChild(instance);
}
function stringToClassInstanceF(s:String):*{
var C:Class=Class(getDefinitionByName(s));
return new C();
}
North America
Europe, Middle East and Africa
Asia Pacific