Pabz
10-02-2009, 04:11 PM
Hi there, i am working on a project where i have been given an FLA that has lots of images contained in movieclips that animate when you roll over them. These animations are all contained on the timeline of each separate movieclip, so the code was basically a lot of gotoAndPlay("2") statements and so on.
I have been given it to work on because the different movieclips need to go to a URL read in from an XML file when clicked on, and i have this part working no problem.
I also need to be able to read in image paths taken from the same XML file as the urls, and load these images into a movieclip holder within the movieclips on the main timeline. However the problem that i am having is once the images are loaded into img_holder which is placed inside a movieclip they will not animate on that movieclip's timeline.
Here is the code placed in frame 1 of the timeline:
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener(Event.COMPLETE, processXML);
myLoader.load(new URLRequest("data.xml"));
function processXML(e:Event):void
{
myXML = new XML(e.target.data);
imgLoader();
}
function imgLoader()
{
var imageLoader1:Loader = new Loader();
var img1Path:String = myXML.item.image[0];
trace(img1Path);
var image1:URLRequest = new URLRequest(img1Path);
imageLoader1.load(image1);
hl1.img_holder.addChild(imageLoader1);
}
stage.addEventListener(MouseEvent.MOUSE_OVER, rollOverTest);
stage.addEventListener(MouseEvent.MOUSE_OUT, rollOutTest);
stage.addEventListener(MouseEvent.CLICK, mouseClickTest);
function rollOverTest(e:Event):void
{
stage.removeEventListener(MouseEvent.MOUSE_OVER, rollOverTest);
if (e.target==mcbodyCopy)
{
mcbodyCopy.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("81")
}
else if (e.target==hl1)
{
hl1.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("3")
}
else if (e.target==hl2)
{
hl2.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("121")
}
else if (e.target==hl3)
{
hl3.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("101")
}
else if (e.target==hl4)
{
hl4.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("21")
}
else if (e.target==hl5)
{
hl5.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("41")
}
else if (e.target==hl6)
{
hl6.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("61")
}
}
function rollOutTest(e:Event):void
{
if (e.target==mcbodyCopy)
{
mcbodyCopy.gotoAndStop("1")
}
else if (e.target==hl1)
{
hl1.gotoAndPlay("11")
}
else if (e.target==hl2)
{
hl2.gotoAndStop("1")
}
else if (e.target==hl3)
{
hl3.gotoAndStop("1")
}
else if (e.target==hl4)
{
hl4.gotoAndPlay("11")
}
else if (e.target==hl5)
{
hl5.gotoAndPlay("11")
}
else if (e.target==hl6)
{
hl6.gotoAndPlay("11")
}
stage.addEventListener(MouseEvent.MOUSE_OVER, rollOverTest);
mcWhiteout.gotoAndPlay("1")
}
function mouseClickTest(e:Event):void
{
if (e.target==hl1)
{
navigateToURL(new URLRequest(myXML.item.url[0]), "_blank");
}
else if (e.target==hl2)
{
navigateToURL(new URLRequest(myXML.item.url[1]), "_blank");
}
else if (e.target==hl3)
{
navigateToURL(new URLRequest(myXML.item.url[2]), "_blank");
}
else if (e.target==hl4)
{
navigateToURL(new URLRequest(myXML.item.url[3]), "_blank");
}
else if (e.target==hl5)
{
navigateToURL(new URLRequest(myXML.item.url[4]), "_blank");
}
else if (e.target==hl6)
{
navigateToURL(new URLRequest(myXML.item.url[5]), "_blank");
}
}
Hope i've explained that clearly enough. Am i going about this completely the wrong way?
I have been given it to work on because the different movieclips need to go to a URL read in from an XML file when clicked on, and i have this part working no problem.
I also need to be able to read in image paths taken from the same XML file as the urls, and load these images into a movieclip holder within the movieclips on the main timeline. However the problem that i am having is once the images are loaded into img_holder which is placed inside a movieclip they will not animate on that movieclip's timeline.
Here is the code placed in frame 1 of the timeline:
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener(Event.COMPLETE, processXML);
myLoader.load(new URLRequest("data.xml"));
function processXML(e:Event):void
{
myXML = new XML(e.target.data);
imgLoader();
}
function imgLoader()
{
var imageLoader1:Loader = new Loader();
var img1Path:String = myXML.item.image[0];
trace(img1Path);
var image1:URLRequest = new URLRequest(img1Path);
imageLoader1.load(image1);
hl1.img_holder.addChild(imageLoader1);
}
stage.addEventListener(MouseEvent.MOUSE_OVER, rollOverTest);
stage.addEventListener(MouseEvent.MOUSE_OUT, rollOutTest);
stage.addEventListener(MouseEvent.CLICK, mouseClickTest);
function rollOverTest(e:Event):void
{
stage.removeEventListener(MouseEvent.MOUSE_OVER, rollOverTest);
if (e.target==mcbodyCopy)
{
mcbodyCopy.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("81")
}
else if (e.target==hl1)
{
hl1.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("3")
}
else if (e.target==hl2)
{
hl2.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("121")
}
else if (e.target==hl3)
{
hl3.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("101")
}
else if (e.target==hl4)
{
hl4.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("21")
}
else if (e.target==hl5)
{
hl5.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("41")
}
else if (e.target==hl6)
{
hl6.gotoAndPlay("2")
mcWhiteout.gotoAndPlay("61")
}
}
function rollOutTest(e:Event):void
{
if (e.target==mcbodyCopy)
{
mcbodyCopy.gotoAndStop("1")
}
else if (e.target==hl1)
{
hl1.gotoAndPlay("11")
}
else if (e.target==hl2)
{
hl2.gotoAndStop("1")
}
else if (e.target==hl3)
{
hl3.gotoAndStop("1")
}
else if (e.target==hl4)
{
hl4.gotoAndPlay("11")
}
else if (e.target==hl5)
{
hl5.gotoAndPlay("11")
}
else if (e.target==hl6)
{
hl6.gotoAndPlay("11")
}
stage.addEventListener(MouseEvent.MOUSE_OVER, rollOverTest);
mcWhiteout.gotoAndPlay("1")
}
function mouseClickTest(e:Event):void
{
if (e.target==hl1)
{
navigateToURL(new URLRequest(myXML.item.url[0]), "_blank");
}
else if (e.target==hl2)
{
navigateToURL(new URLRequest(myXML.item.url[1]), "_blank");
}
else if (e.target==hl3)
{
navigateToURL(new URLRequest(myXML.item.url[2]), "_blank");
}
else if (e.target==hl4)
{
navigateToURL(new URLRequest(myXML.item.url[3]), "_blank");
}
else if (e.target==hl5)
{
navigateToURL(new URLRequest(myXML.item.url[4]), "_blank");
}
else if (e.target==hl6)
{
navigateToURL(new URLRequest(myXML.item.url[5]), "_blank");
}
}
Hope i've explained that clearly enough. Am i going about this completely the wrong way?