Hello there,
I’m trying to make a banner with a dynamic news slider (News copy+header + picture).
For this I found this fantastic tutorial, which was exactly what I needed.
http://www.faustocarrera.com.ar/v2/automated-news-slider-with-as3/
Everything works like a charm, just until I want to dublicate f.x. the imageloader, and make a mirror effect with it.
What I thought of was just giving the flipped movieclip another instancename
function loadNews(num:int):void
{
activeNews = num;
//hide the buttons
IMGloader_mc.goto_btn.enabled = false;
prev_btn.enabled = false;
next_btn.enabled = false;
IMGloader_mc.holder_mc.addChild(imagesClips_arr[num]);
// IMGloader2_mc.holder_mc.addChild(imagesClips_arr[num]);
display_mc.title_txt.text = title_arr[num];
display_mc.desc_txt.text = description_arr[num];
IMGloader_mc.goto_btn.enabled = true;
prev_btn.enabled = true;
next_btn.enabled = true;
IMGloader_mc.link = url_arr[num];
}
The line I have commented, is the line I have added to put the loaded picture inside of the holder_mc.
IMGloader_mc and IMGloader2_mc is exact the same movieclips - just with different instancenames.
When I do this, I actually get the image to load in IMGloader2_mc.holder_mc, but isn’t no picture in IMGloader_mc.holder_mc then!
What the ****?
I have tried to figure out several solution, but without luck… It seems that the loaded picture can only be shown ONCE
I have putted the files on my website: www.grubbe.org/flash/news_slider.zip
I truly hope, that someone is able to help me out here - I’m lost
Regards,
Jacob
Code:
Frame 2:
stop();
/* arrays to hold the info */
var title_arr:Array = [];
var description_arr:Array = [];
var image_arr:Array = [];
var url_arr:Array = [];
var imagesClips_arr:Array = [];
/* load the xml */
var xml_url:String = "xml/flash_news.xml";
var news_data:XML = new XML();
var news_url:URLRequest = new URLRequest(xml_url);
var newsLoader:URLLoader = new URLLoader(news_url);
newsLoader.addEventListener(Event.COMPLETE, newsLoaded);
function newsLoaded(e:Event):void
{
news_data = XML(newsLoader.data);
//recorrer el xml
var allNews:XMLList = news_data.*;
for each (var news:XML in allNews)
{
title_arr.push(news.title.toString());
description_arr.push(news.description.toString());
image_arr.push(news.image.toString());
url_arr.push(news.url.toString());
}
//
loadImages();
}
/* preload the images and add it to empty movieclips */
var count:int = 0;
function loadImages():void
{
var toLoad:int = image_arr.length;
if (count > toLoad-1)
{
gotoAndStop("display");
}
else
{
preloader_txt.text = "preloading image "+(count+1);
//here load the image
var mc:MovieClip = new MovieClip;
imagesClips_arr.push(mc);
var img_url:String = "images/"+image_arr[count];
var loader:Loader = new Loader();
var request_url:URLRequest = new URLRequest(img_url);
loader.load(request_url);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListener);
function completeListener(e:Event):void
{
mc.addChild(loader.content);
}
count++;
loadImages();
}
}
Frame 3:
stop();
/* ini variables */
var activeNews:int = 0;
var isPlaying:Boolean = true;
var totalNews:int = title_arr.length;
/* timer */
var timer:Timer = new Timer(15000, 0);
timer.addEventListener(TimerEvent.TIMER, timerListener);
function timerListener(e:TimerEvent)
{
if (activeNews == totalNews-1)
{
loadNews(0);
}
else
{
loadNews(activeNews+1);
}
//trace("running!!");
}
timer.start();
/* load the news */
function loadNews(num:int):void
{
activeNews = num;
//hide the buttons
IMGloader_mc.goto_btn.enabled = false;
prev_btn.enabled = false;
next_btn.enabled = false;
IMGloader_mc.holder_mc.addChild(imagesClips_arr[num]);
IMGloader2_mc.holder_mc.addChild(imagesClips_arr[num]);
display_mc.title_txt.text = title_arr[num];
display_mc.desc_txt.text = description_arr[num];
IMGloader_mc.goto_btn.enabled = true;
prev_btn.enabled = true;
next_btn.enabled = true;
IMGloader_mc.link = url_arr[num];
}
/* next prev and pause */
prev_btn.addEventListener(MouseEvent.CLICK, prevListener);
function prevListener(e:MouseEvent):void
{
if (activeNews == 0)
{
loadNews(totalNews-1);
}
else
{
loadNews(activeNews-1);
}
timer.reset();
timer.start();
}
next_btn.addEventListener(MouseEvent.CLICK, nextListener);
function nextListener(e:MouseEvent):void
{
if (activeNews == totalNews-1)
{
loadNews(0);
}
else
{
loadNews(activeNews+1);
}
timer.reset();
timer.start();
}
pause_btn.addEventListener(MouseEvent.CLICK, pauseListener);
function pauseListener(e:MouseEvent):void
{
if (isPlaying)
{
isPlaying = false;
timer.stop();
timer.reset();
//
pause_btn.alpha = 0.8;
}
else
{
isPlaying = true;
timer.start();
//
pause_btn.alpha = 1;
}
}
/* load the first news */
loadNews(0);