Jump to content
Search Community

n00b need help :(

Aksel test
Moderator Tag

Recommended Posts

Hi all.

 

I've been struggling a bit with a slideshow I'm trying to create. It's working at the moment as intended..however.. Currently I'm preloading some images from my xml file..apparantly it loads all images before displaying them. As you noticed by now probably, i'm very new to flash, so excuse my ignorance to the field :)

 

What I'm trying to achieve is:

 

Preload the FIRST image and displaying it, before loading the other images so that there won't be an empty stage while the user waits for the other images to load.

 

I just recently came across the Loading class you have ..and haven't yet managed to implement this..so I hope you wizards may help me on my way :)

 

The current code I've been using is:

 

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;

var my_speed:Number;
var my_total:Number;
var my_images:XMLList;


Mouse.cursor = "button";
var my_loaders_array:Array=[];
var my_labels_array:Array=[];
var my_success_counter:Number=0;
var my_playback_counter:Number=0;

var my_slideshow:Sprite = new Sprite();
var my_image_slides:Sprite = new Sprite();
var my_label_slides:Sprite = new Sprite();
var my_preloader:TextField;

var my_timer:Timer;
var my_prev_tween:Tween;
var my_tweens_array:Array=[];

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

function processXML(e:Event):void {
var my_xml:XML=new XML(e.target.data);
my_speed=my_xml.@SPEED;
my_images=my_xml.IMAGE;


my_total=my_images.length();

loadImages();

my_xml_loader.removeEventListener(Event.COMPLETE, processXML);
my_xml_loader=null;
}

function loadImages():void {
for (var i:Number = 0; i < my_total; i++) {
	var my_url:String=my_images[i].@URL;
	var my_loader:Loader = new Loader();
	my_loader.load(new URLRequest(my_url));
	my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
	my_loaders_array.push(my_loader);

	var my_label:TextField = new TextField();
	my_label.text=my_images[i].@TITLE;

	my_label.autoSize=TextFieldAutoSize.LEFT;
	my_labels_array.push(my_label);

}

my_preloader = new TextField();
my_preloader.text="Laster inn bilder...";
my_preloader.autoSize=TextFieldAutoSize.CENTER;
my_preloader.x = (stage.stageWidth - my_preloader.width)/2;
my_preloader.y = (stage.stageHeight - my_preloader.height)/2;
addChild(my_preloader);

}

function onComplete(e:Event):void {

my_success_counter++;
if (my_success_counter==my_total) {
	startShow();
}

var my_loaderInfo:LoaderInfo=LoaderInfo(e.target);
my_loaderInfo.removeEventListener(Event.COMPLETE, onComplete);

}

function startShow():void {

removeChild(my_preloader);
my_preloader=null;

addChild(my_slideshow);
my_slideshow.addChild(my_image_slides);
my_slideshow.addChild(my_label_slides);

nextImage();

my_timer=new Timer(my_speed*1000);

my_timer.addEventListener(TimerEvent.TIMER, timerListener);
my_timer.start();

}

function nextImage():void {

var my_image:Loader=Loader(my_loaders_array[my_playback_counter]);
my_image.addEventListener(MouseEvent.CLICK, klikketbilde);
my_image_slides.addChild(my_image);
my_image.x = (stage.stageWidth - my_image.width)/2;
my_image.y = (stage.stageHeight - my_image.height)/2;
my_tweens_array[0]=new Tween(my_image,"alpha",Strong.easeOut,0,1,1,true);




var my_label:TextField=TextField(my_labels_array[my_playback_counter]);

my_label_slides.addChild(my_label);
my_label.x=my_image.x;
my_label.y=my_image.y+my_image.height;
my_tweens_array[1]=new Tween(my_label,"alpha",Strong.easeOut,0,1,1,true);

}

function timerListener(e:TimerEvent):void {

hidePrev();

my_playback_counter++;
if (my_playback_counter==my_total) {
	my_playback_counter=0;
}
nextImage();

}

function hidePrev():void {

var my_image:Loader=Loader(my_image_slides.getChildAt(0));
my_prev_tween=new Tween(my_image,"alpha",Strong.easeOut,1,0,1,true);
my_prev_tween.addEventListener(TweenEvent.MOTION_FINISH, onFadeOut);

var my_label:TextField=TextField(my_label_slides.getChildAt(0));
my_tweens_array[2]=new Tween(my_label,"alpha",Strong.easeOut,1,0,1,true);

}

function onFadeOut(e:TweenEvent):void {
my_image_slides.removeChildAt(0);
my_label_slides.removeChildAt(0);
}

function klikketbilde(e:MouseEvent):void{

var my_image:Loader=Loader(my_loaders_array[my_playback_counter]);

my_timer.stop();
//my_images[i].@TITLE;


switch(my_image.name){
	case "instance4":

	navigateToURL(new URLRequest(my_images[0].@TITLE),"_self");
	break;

	case "instance7":
	navigateToURL(new URLRequest(my_images[1].@TITLE),"_self");
	break;

	case "instance10":
	navigateToURL(new URLRequest(my_images[2].@TITLE),"_self");
	break;

	case "instance13":
	navigateToURL(new URLRequest(my_images[3].@TITLE),"_self");
	break;

	case "instance16":
	navigateToURL(new URLRequest(my_images[4].@TITLE),"_self");
	break;

	case "instance19":
	navigateToURL(new URLRequest(my_images[5].@TITLE),"_self");
	break;


}
}

Link to comment
Share on other sites

Yep, this should be relatively easy with LoaderMax. You'd just create your first ImageLoader, listen for its COMPLETE event, and then populate a LoaderMax instance with the rest of your ImageLoaders and load() it in the background.

 

In case it's helpful, there's a LoaderMax-based slideshow at http://www.greensock.com/as/docs/tween/_loadermax.html

Link to comment
Share on other sites

Thanks for your reply :)

 

Now I have a few more (probably stupid) questions...but bare with me please :)

 

This is the code I have now to load the xml file and its images:

 

script.as:

package scriptet{
import com.greensock.loading.ImageLoader;
import com.greensock.events.LoaderEvent;
import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.loading.display.*;
import flash.display.Sprite;
import flash.utils.Timer;

public class script extends Sprite{

	var my_speed:Number;
	var my_total:Number;
	var my_images:XMLList;
	var my_timer:Timer;


	public function script(){

	LoaderMax.activate([imageLoader]);
	var loader:XMLLoader = new XMLLoader("slideshow.xml", {onComplete:completeHandler, estimatedBytes:50000});
	loader.load();


	function completeHandler(event:LoaderEvent):void {
   	trace("XML and queue1 loaded!");
   	addChild( LoaderMax.getContent("image1") );
   	addChild( LoaderMax.getContent("image2") );
	addChild( LoaderMax.getContent("image3") );

   	//grab the LoaderMax named "queue2" that was defined in the XML and start loading it now
   	var queue2:LoaderMax = LoaderMax.getLoader("queue2");
   	queue2.addEventListener(LoaderEvent.COMPLETE, queue2CompleteHandler);
   	queue2.load();
	}

function queue2CompleteHandler(event:LoaderEvent):void {
   trace("queue2 loaded!");
}

	}

}
}


 

Slideshow.xml:

 

<?xml version="1.0" encoding="iso-8859-1"?>










 

Now from what I understand, the first image is loaded by itself and displayed before it starts loading queue # 2. Which is great, and what I wanted to do.

 

Now for the next goal:

 

Start the slideshow, tweening between the images loaded. Preferably with a timer speed set up in the XML file which I had in my old code like this:

 my_speed=my_xml.@SPEED;

This didn't seem to work with the greensock.loading.XMLLoader class.

 

I'm also trying to attach a link to each images set in the xml file. In my old code i just used the "Title" tag in the xml file where i set up a clickable link which is added to each image in the slideshow.

 

Sorry again for probably some complete basic questions here...but I'm very new to this so trying to learn as I go. Thanks in advance for any help you might provide!

Link to comment
Share on other sites

Start the slideshow, tweening between the images loaded. Preferably with a timer speed set up in the XML file which I had in my old code like this:
 my_speed=my_xml.@SPEED;

This didn't seem to work with the greensock.loading.XMLLoader class.

It's tough to know why it didn't work for you without seeing your XML and AS3 code. But it's definitely possible. To learn how to parse through your XML and find the data you want, check out Senocular's great article at http://www.senocular.com/flash/tutorial ... page=4#e4x There is also examples of this in the slideshow.zip I linked you to in the last post.

 

I'm also trying to attach a link to each images set in the xml file. In my old code i just used the "Title" tag in the xml file where i set up a clickable link which is added to each image in the slideshow.

Again, check out the slideshow.zip files because it has stuff in there that could help on this. Feel free to whip together a sample FLA (as simple as possible) with your attempt to make this happen and post it here to get help.

 

Oh, and by the way, I would strongly recommend NOT using nested functions. They're considered a poor practice in ActionScript because they can cause garbage collection problems.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...