Hi!
I’m new to actionscript but I want to learn and I started to experiment things. First of all I’ve made a small drag&drop with all images and movieclips already in library, worked like a dream. After that I wanted to take the next step … loading them dynamic and here is the problem:
On the scene I don’t have any items or in library because I want to control everything from actionscript
For my drag and drop I have to call movieclips by instance names and here is my big problem making Flash to keep my instance names or I’m an idiot and I can’t call them
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<images COLUMNS="5" >
<image nume="c1" >img/c1.jpg</image>
<image nume="c2" >img/c2.jpg</image>
<image nume="c3" >img/c3.jpg</image>
<image nume="c4" >img/c4.jpg</image>
<image nume="c5" >img/c5.jpg</image>
<image nume="c6" >img/c6.jpg</image>
<image nume="e1" >img/e1.jpg</image>
<image nume="e2" >img/e2.jpg</image>
</images>
Here I load this XML and populate two arrays - one with names and one with URL path:
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("drag.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);
my_images = myXML.image;
my_total = my_images.length();
for (var i:uint=0; i<my_total; i++) {
catarr.push(myXML.image.@nume*);
imgarr.push(myXML.image*);
}
Now, I have a function for loading those images:
function loadPicture () {
for (var k:uint = 0; k<imgarr.length; k++) {
var request:URLRequest = new URLRequest(imgarr[k]);
var loader:Loader = new Loader();
myMC = new MovieClip();
loader.load(request);
this.myMC.addChild(loader);
this.addChild(myMC);
this.myMC.name = catarr[k];
this.myMC.x =100 + (k * 100);
trace(myMC.name);
}
}
Ok, and now I want to position on different y picture names starting with “c” and picture names starting with “e”.
And here I’m stuck … if I add this to loadPicture function:
if(this.myMC.name == "c1"){
this.myMC.y = 20;
}
else {
this.myMC.y = 60;
}
it works but I have to write all names an if I will change the xml to add some pictures I will have to reopen my fla and also change the script to add more “c” names. If I put this in a “for”:
for (var j=1; j<=6; j++){
if (this.myMC.name == "c"+j ){
this.myMC.y = 10;
}
else{
this.myMC.y = 100;
}
}
I get only the last “c” picture at y=10
It not bother me that I can do it with grandma’ method (put an else if for each “c”) but since I wish to learn I want to know the other solution.
Anyone can help?
Thanks