Jump to content
Search Community

XMLList not found

SyntaxMind test
Moderator Tag

Recommended Posts

Jack I remembered what you said about not having to create a new ImageLoader every time I want to load an image. After looking at different tutorials, I still couldn't find an example of how that would be done so I tried again to reconstruct a cleaner version. My wall now is get an XMLLIST array. As you can see I tried to add next/prev button clicks but am having a problem with an array.length(). If you look in the click function the commented code gives me an error. How would I add an XMLLIST to this?

 

 

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











 

package 
{

import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.DisplayObject;

import com.greensock.TweenMax;
import com.greensock.layout.*;
import com.greensock.loading.LoaderMax;
import com.greensock.loading.XMLLoader;
import com.greensock.loading.ImageLoader;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.ContentDisplay;
import com.greensock.loading.data.XMLLoaderVars;


public class Main extends MovieClip
{

	public var imgHolder:MovieClip;

	private var ls:LiquidStage;
	private var la:LiquidArea;
	private var xml:XMLLoader;
	private var index:int = 0;
	private var images:Array;


	public function Main()
	{
		arrowRight.alpha = arrowLeft.alpha = 0;
		xmlLoader();
	}

	private function xmlLoader():void
	{
		LoaderMax.activate([imageLoader]);
		xml = new XMLLoader("assets/data.xml", new XMLLoaderVars()
												.name("loader")
												.onComplete(xmlLoaded)
												.onProgress(loadProgress));
		xml.load();
	}

	private function xmlLoaded(e:LoaderEvent):void
	{
		trace("Loaded");
		arrowListeners();
		showImage(index);
	}

	private function loadProgress(event:LoaderEvent):void
	{
		progressMC.progressBar.scaleX = event.target.progress;
	}

	private function showImage(index:int):void
	{
		var images = LoaderMax.getContent("loader"); 

           imgHolder.addChild(images[index]);

           images[index].width = stage.stageWidth;
           images[index].height = stage.stageHeight;

           //fade it in
           TweenMax.from(images[index], 1, {alpha:0});
	}

	private function arrowListeners():void
	{
		arrowRight.addEventListener(MouseEvent.ROLL_OVER, rollOverArrowHandler, false, 0, true);
		arrowRight.addEventListener(MouseEvent.ROLL_OUT, rollOutArrowHandler, false, 0, true);
		arrowRight.addEventListener( MouseEvent.CLICK, onRightClick );
		arrowLeft.addEventListener(MouseEvent.ROLL_OVER, rollOverArrowHandler, false, 0, true);
		arrowLeft.addEventListener(MouseEvent.ROLL_OUT, rollOutArrowHandler, false, 0, true);
		arrowLeft.addEventListener( MouseEvent.CLICK, onLeftClick );
	}

	private function rollOverArrowHandler(e:MouseEvent):void
	{
		TweenMax.to(e.currentTarget, 0.5, {alpha:1});
	}

	private function rollOutArrowHandler(e:MouseEvent):void
	{
		TweenMax.to(e.currentTarget, 0.5, {alpha:0});
	}

	// click handler for arrows
	private function onRightClick( e:MouseEvent ):void
	{
		index++
		/*if (index > images.length()) 
		{
			index = 0;
		}*/
		showImage(index);


	}

	private function onLeftClick( e:MouseEvent ):void
	{
		index--
		/*if (index < 0) 
		{
			index = images.length() - 1;
		}*/
		showImage(index);
	}

}
}

Link to comment
Share on other sites

I believe your issues are 2 fold.

 

1 - your images var is declared inside a function and thus your click function has no knowledge of its existence.

 

2 - as you correctly guessed you want to get an XMLList of all the ImageLoader nodes inside your xml file.

 

---

 

for issue 1 just make sure you define images outside of any functions.

 

var images:XMLList;

 

then once your xml loads you can get an XMLList like so

 

images = xml.content..ImageLoader

trace(images);
trace("\n images.length()  = " + images.length());

Link to comment
Share on other sites

i'm seeing now that i could have completely misunderstood your questions / problem.

 

i saw var images declared in showImage function but you ALSO have it declared at the top of your class which threw me off.

 

 

for the rest of it, I don't think I follow exactly what you are doing, so please forgive my previous advice.

I assumed you wanted an XMLList so that you could parse the xml and create image loaders on request, but I see that you are loading with autoLoad:true so I don't know what you want the XMLList for.

 

it seems your showImage function wants to go through an array of already loaded images and display them based on a provided index?

Link to comment
Share on other sites

sorry for all the confusion, but i think this is what you want:

 

private function showImage(index:int):void
     {

//no "var" in the next line

       images = LoaderMax.getContent("loader"); 

//images is already declared as an array up top.

           imgHolder.addChild(images[index]);

           images[index].width = stage.stageWidth;
           images[index].height = stage.stageHeight;

           //fade it in
           TweenMax.from(images[index], 1, {alpha:0});
     }

 

 

and in your troublesome function:

 

private function onLeftClick( e:MouseEvent ):void
     {
        index--
        if (index          {
           index = images.length- 1;
        }
        showImage(index);
     }

  }

 

you had images.length() should only be images.length

 

XMLList uses the length() method

Array has a length property

 

 

otherwise it looks like you are doing everything right.

 

I don't think you need an XMLList for anything. You have the content of "loader" which is an array of the content of all the loaders in "loader".

 

let me know if you need anything else.

 

I really hope this helps. sorry for the previous distractions.

 

 

 

Carl

Link to comment
Share on other sites

Hey carl sorry for the late reply.

 

After a few responses it seems you figured out what I was trying to do. To explain further, I am just wanting to create a slideshow with next and prev buttons and possibly create a timer event of some sort for the next image. But for now the buttons.

 

Looking at your last message, it seems you have come to the same conclusion I had given you are saying that the only change I should make is to the length() method/property. I didn't think I needed an XMLList either because images was already an array on the content "loader" and also .length() was a typo. But when I traced either images.length() or images.length, I get either null or this error: "TypeError: Error #1009: Cannot access a property or method of a null object reference at Main/onRightClick()". So I figured in or to write an if statement to check if the click is on the last images was XMLList, but now I'm stuck. I hope this clears it up. If so, please help with my bad coding.

Link to comment
Share on other sites

Fixed!!!

 

Thanks carl. I happen to read more through your posts and noticed I declared var images in the function and already gave a private var to images inside the class. I removed var in the showImage function and images.length traces now. Your post helped a lot.

 

I do have one last fix issue. The progress bar is jerky and Im not sure why. It starts at 100 percent then jumps to the actual percentage loading. Can you see where I messed that up?

Link to comment
Share on other sites

glad to hear you got it worked out. Thanks for letting me know, I was just about to look into it more.

 

I believe the problem you are having now is that you aren't defining estimatedBytes on your XMLLoader

 

from the documentation:

 

estimatedBytes : uint - Initially, the loader's bytesTotal is set to the estimatedBytes value (or LoaderMax.defaultEstimatedBytes if one isn't defined). Then, when the XML has been loaded and analyzed enough to determine the size of any dynamic loaders that were found in the XML data (like nodes, etc.), it will adjust the bytesTotal accordingly. Setting estimatedBytes is optional, but it provides a way to avoid situations where the progress and bytesTotal values jump around as XMLLoader recognizes nested loaders in the XML and audits their size. The estimatedBytes value should include all nested loaders as well, so if your XML file itself is 500 bytes and you have 3 tags with load="true" and each image is about 2000 bytes, your XMLLoader's estimatedBytes should be 6500. The more accurate the value, the more accurate the loaders' overall progress will be.

 

also read tip 9: http://www.greensock.com/loadermax-tips/

 

----

 

basically what you are experiencing is this.

 

your XMLLoader loads an xml file. while that file is loading XMLLoader is thinking, "man, my job is easy, this is just a simple text file... hey look at me, I'm done!" and then it realizes "Oh NO! this file wants me to load 8 more images! I better adjust my progress and call the wife, I'm not getting out of here for awhile"

 

so basically figure out a round estimate of the file size of all your images AND your xml file combined and pass that in as the estimatedBytes in the XMLLoader constructor vars.

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...