Hey guys,
I’m working on a tag-driven XML-menu. The XML consists of links to images and tags. There are two different kinds of tags. Maintags are describing the image itself and reftags are reffering to similar images. So if you click on a MovieClip (with embedded image) the image’s reftag should refer to the maintag of another (related) image, which now should be loaded into the MovieClip.
I’m stuck with coding this thing. Actually I understand what to do, but I can’t help myself to translate it into Actionscript.
Here’s my code:
(htag stands for maintag and objekt for object (in this case image)
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
var externalXML:XML;
var objekte = [];
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("objekte.xml");
loader.load(request);
loader.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void
{
var loader:URLLoader = event.target as URLLoader;
if (loader != null)
{
externalXML = new XML(loader.data);
trace(externalXML.toXMLString());
}
externalXML.ignoreWhitespace = true;
for (var i:uint = 0; i < externalXML.objekt.length(); i++) {
var objekt = new Object(); objekt.obj_source = externalXML.objekt*.obj_source;
objekt.obj_name = externalXML.objekt*.obj_name;
objekt.htag = externalXML.objekt*.htag;
objekt.tagArray = new Array();
for each(var s:String in externalXML.objekt*.tag) objekt.tagArray.push(s);
objekte* = objekt;
}
function loadObjekt():void
{
while (numChildren > 0) removeChildAt(0);
for(var i:uint = 0; i < objekte.length; i++)
{
var loader:Loader = new Loader();
loader.load(new URLRequest(objekte[nr - 1].obj_source));
loader.addEventListener(MouseEvent.CLICK, onClick);
addChild(loader);
}
}
function onClick(e:Event):void
{
var index:uint = getChildIndex(DisplayObject(e.target));
var tag:String = objekte[index].htag;
var fullTagList:Array = [tag];
for each(var i:String in objekte[index].tagArray) fullTagList.push(objekte[uint(i)].htag);
}
The XML:
<?xml version="1.0" ?>
<objekte>
<objekt id="1">
<obj_name>testimg1</obj_name>
<obj_source>pic1.png</obj_source>
<h_tag>one</h_tag>
<tag>two</tag>
<tag>three</tag>
</objekt>
<objekt id="2">
<obj_name>testimg2</obj_name>
<obj_source>pic2.png</obj_source>
<h_tag>two</h_tag>
<tag>three</tag>
<tag>four</tag>
</objekt>
<objekt id="3">
<obj_name>testimg3</obj_name>
<obj_source>pic3.png</obj_source>
<h_tag>three</h_tag>
<tag>four</tag>
<tag>five</tag>
</objekt>
<objekt id="4">
<obj_name>testimg4</obj_name>
<obj_source>pic4.png</obj_source>
<h_tag>four</h_tag>
<tag>five</tag>
<tag>six</tag>
</objekt>
<objekt id="5">
<obj_name>testimg5</obj_name>
<obj_source>pic5.png</obj_source>
<h_tag>five</h_tag>
<tag>six</tag>
<tag>one</tag>
</objekt>
<objekt id="6">
<obj_name>testimg6</obj_name>
<obj_source>pic6.png</obj_source>
<h_tag>six</h_tag>
<tag>onw</tag>
<tag>two</tag>
</objekt>
</objekte>
Example:
You click on a MovieClip with testimg2 -> testimg3 and testimg4 now should be loaded.
The next thing is that there should be only 6 MovieClips (parts of a cube) but more than 50 images. There must be some kind of limit, when there are more than 6 images which have been reffered to. But this is future :}
Any help is highly appreciated!
monde.