Repeat code or what?

Here's my problem, I made a gallery using an on-line tutorial and it works in treating the xml file. What I want to do is to repeat this code on a different image, but referencing a different xml - so receive different images. I tried just copy - paste it but of course it did not work.

I tried to separated variable string in which I will put the name of my xml file, then from the Gallery code, I reference just this variable. But it does not work either. It's like when the code runs once it won't run more although even its tru "spread" several images, not copied on different keyframes.

Is there an easy way to do what im triing to do?

The Gallery code:

Import fl.controls.ProgressBar;

Import fl.transitions.Tween;

Fl.transitions.easing import. *;

Import fl.transitions.TweenEvent;

columns: number var;

var my_x:Number;

var my_y:Number;

var my_thumb_width:Number;

var my_thumb_height:Number;

var my_images:XMLList;

var my_total:Number;

var container_mc:MovieClip;

var preloaders_mc:MovieClip;

var full_mc:MovieClip;

var x_counter:Number = 0;

var y_counter:Number = 0;

var my_tweens:Array = [];

var container_mc_tween:Tween;

var full_tween:Tween;

var myXMLLoader:URLLoader = new URLLoader();

myXMLLoader.load (new URLRequest (xml));

myXMLLoader.addEventListener (Event.COMPLETE, processXML);

function processXML(e:Event):void {}

var myXML:XML = new XML (e.target.data);

columns = myXML.@COLUMNS;

my_x = myXML.@XPOSITION;

my_y = myXML.@YPOSITION;

my_thumb_width = myXML.@WIDTH;

my_thumb_height = myXML.@HEIGHT;

my_images = myXML.IMAGE;

my_total = my_images.length ();

createContainer();

callThumbs();

myXMLLoader.removeEventListener (Event.COMPLETE, processXML);

myXMLLoader = null;

}

function createContainer (): void {}

container_mc = new MovieClip();

container_mc.x = my_x;

container_mc.y = my_y;

addChild (container_mc);

container_mc.addEventListener (MouseEvent.CLICK, callFull);

container_mc.addEventListener (MouseEvent.MOUSE_OVER, onOver);

container_mc.addEventListener (MouseEvent.MOUSE_OUT, procedure);

container_mc.buttonMode = true;

preloaders_mc = new MovieClip();

preloaders_mc.x = container_mc.x;

preloaders_mc.y = container_mc.y;

addChild (preloaders_mc);

}

function callThumbs (): void {}

for (var i: Number = 0; i < my_total; i ++) {}

var thumb_url = my_images[i].@THUMB;

var thumb_loader = new Loader();

thumb_loader. Load (new URLRequest (thumb_url));

thumb_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, thumbLoaded);

thumb_loader. Name = i;

thumb_loader.x = (my_thumb_width + 10) * x_counter;

thumb_loader.y = (my_thumb_height + 10) * y_counter;

If (x_counter + 1 < columns) {}

x_counter ++;

} else {}

x_counter = 0;

y_counter ++;

}

var preloader_pb:ProgressBar = new ProgressBar();

preloader_pb.source = thumb_loader.contentLoaderInfo;

preloader_pb.x = thumb_loader.x;

preloader_pb.y = thumb_loader.y;

preloader_pb. Width = my_thumb_width;

preloader_pb. Height = my_thumb_height;

preloaders_mc. AddChild (preloader_pb);

preloader_pb.addEventListener (Event.COMPLETE, donePb);

}

}

function thumbLoaded(e:Event):void {}

var my_thumb:Loader = Loader (e.target.loader);

container_mc. AddChild (my_thumb);

my_tweens [Number (my_thumb. (Name)] = new Tween (Strong.easeIn, 0,1,0.5, my_thumb, "alpha", true);

my_thumb.contentLoaderInfo.removeEventListener (Event.COMPLETE, thumbLoaded);

}

function callFull(e:MouseEvent):void {}

var full_loader:Loader = new Loader();

var full_url = my_images[e.target.name].@FULL;

full_loader. Load (new URLRequest (full_url));

full_loader.contentLoaderInfo.addEventListener (Event.INIT, fullLoaded);

var full_pb:ProgressBar = new ProgressBar();

full_pb.source = full_loader.contentLoaderInfo;

full_pb.x = (stage.stageWidth - full_pb.width) / 2;

full_pb.y = (stage.stageHeight - full_pb.height) / 2;

preloaders_mc. AddChild (full_pb);

full_pb.addEventListener (Event.COMPLETE, donePb);

container_mc. RemoveEventListener (MouseEvent.CLICK, callFull);

container_mc.buttonMode = false;

container_mc. RemoveEventListener (MouseEvent.MOUSE_OVER, onOver);

container_mc. RemoveEventListener (MouseEvent.MOUSE_OUT, procedure);

container_mc_tween = new Tween (container_mc, "alpha", Strong.easeIn, 1,0.5,0.5, true);

}

function fullLoaded(e:Event):void {}

full_mc = new MovieClip();

full_mc.buttonMode = true;

addChild (full_mc);

var my_loader:Loader = Loader (e.target.loader);

full_mc. AddChild (my_loader);

full_tween = new Tween (Strong.easeIn, 0,1,0.5, my_loader, "alpha", true);

my_loader.x = (stage.stageWidth - my_loader.width) / 2;

my_loader.y = (stage.stageHeight - my_loader.height) / 2;

my_loader.addEventListener (MouseEvent.Click, removeFull);

my_loader.contentLoaderInfo.removeEventListener (Event.COMPLETE, fullLoaded);

}

function removeFull(e:MouseEvent):void {}

var my_loader:Loader = Loader (e.currentTarget);

full_tween = new Tween (Strong.easeOut, 1,0,0.5, my_loader, "alpha", true);

full_tween.addEventListener (TweenEvent.MOTION_FINISH, tweenFinished);

container_mc_tween = new Tween (container_mc, "alpha", Strong.easeOut, 0.5,1,0.5, true);

}

function donePb(e:Event):void {}

var my_pb:ProgressBar = ProgressBar (e.target);

preloaders_mc.removeChild (my_pb);

my_pb. RemoveEventListener (Event.COMPLETE, donePb);

}

function tweenFinished(e:TweenEvent):void {}

var my_loader:Loader = Loader (e.target.obj);

my_loader. Unload();

full_mc.removeChild (my_loader); / / This line was removeChid (my_loader), simply add full_mc in front of him.

removeChild (full_mc);

full_mc = null;

container_mc.addEventListener (MouseEvent.CLICK, callFull);

container_mc.buttonMode = true;

container_mc.addEventListener (MouseEvent.MOUSE_OVER, onOver);

container_mc.addEventListener (MouseEvent.MOUSE_OUT, procedure);

var my_tween:Tween = Tween (e.target);

my_tween. RemoveEventListener (TweenEvent.MOTION_FINISH, tweenFinished);

}

function onOver(e:MouseEvent):void {}

var my_thumb:Loader = Loader (e.target);

my_thumb.Alpha = 0.5;

}

function onOut(e:MouseEvent):void {}

var my_thumb:Loader = Loader (e.target);

my_thumb.Alpha = 1;

}

Code Gallery of buttons:

G1.addEventListener (MouseEvent.CLICK, g1g);

function g1g(event:MouseEvent):void {}

removeChild (container_mc)

}

G1.addEventListener (MouseEvent.CLICK, gg1);

function gg1(event:MouseEvent):void {}

gotoAndPlay (108)

}

G2.addEventListener (MouseEvent.CLICK, gg2);

function gg2(event:MouseEvent):void {}

removeChild (container_mc)

}

G2.addEventListener (MouseEvent.CLICK, g2g);

function g2g(event:MouseEvent):void {}

gotoAndPlay (109)

}

G3.addEventListener (MouseEvent.CLICK, gg3);

function gg3(event:MouseEvent):void {}

removeChild (container_mc)

}

G3.addEventListener (MouseEvent.CLICK, g3g);

function g3g(event:MouseEvent):void {}

gotoAndPlay (110)

}

G4.addEventListener (MouseEvent.CLICK, gg4);

function gg4(event:MouseEvent):void {}

removeChild (container_mc)

}

G4.addEventListener (MouseEvent.CLICK, g4g);

function g4g(event:MouseEvent):void {}

gotoAndPlay (111)

}

G5.addEventListener (MouseEvent.CLICK, gg5);

function gg5(event:MouseEvent):void {}

removeChild (container_mc)

}

G5.addEventListener (MouseEvent.CLICK, g5g);

function g5g(event:MouseEvent):void {}

gotoAndPlay (112)

}

Now, we just need to create an interface through which we pass the XML URL for each gallery. Look for this piece of code in your gallery:

var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest(xml));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);

Replace it with this:

var myXMLLoader:URLLoader;

function loadGallery(xml:String):void {
     myXMLLoader = new URLLoader();
     myXMLLoader.load(new URLRequest(xml));
     myXMLLoader.addEventListener(Event.COMPLETE, processXML);
}

In the main timeline to the frame with mc_gallery1, put this code:

mc_gallery1.loadGallery("http://www.mydomain.com/mygallery.xml"); // whatever url to your XML file

I think, you good to go.

Tags: Adobe Animate

Similar Questions

Maybe you are looking for

  • Equium A100-063 - keyboard is not recognized

    Hi all I have a Toshiba Equium A100-063 (PSAAQE-00G006IT).The keyboard does not work, the usb keyboard does not work even in the bios.I disassembled the PC and unplugged the keyboard but does not work (even in bios).I formatted the PC and even the on

  • IPod nano keeps talking. I handed out the voice and is still talking

    My nano keeps announcing songs and options.  I have disabled the voice during the option and the voice of advice in general settings but still keep talking all the time.

  • Tecra S1: dead graphics card - need new motherboard

    I encountered a problem with my Tecra S1, the lcd screen does not light and it gives a system of sound signals.After looking on the net, I concluded that the problem is with the graphics card which is integrated into the motherboard, but I can't find

  • hold time

    my computer keeps rite time. any suggestion?

  • Windows Update will always on a blank page

    Original title : No matter how I try to load my windows update page page still fails to load even though it says that I have updates available. Help The page is empty and said don't load, I tried the download fixit from microsoft but that no longer w