Jump to content
Search Community

String to Object?

ShortBus test
Moderator Tag

Recommended Posts

Hi All & good day-

 

Another newb question here :?

I need "thumb" to be an object instead of a string.

I've xml nodes that consist of


I can access "thumb" through vars but it comes up a string

assets/thumbnails/movie1.swf
assets/thumbnails/movie2.swf
assets/thumbnails/movie3.swf
assets/thumbnails/movie4.swf

 

This is how I'm approaching it

var xmlLoader:XMLLoader = new XMLLoader("assets/data.xml", {name:"assetList",
									onProgess:progressHandler,
									onComplete:xmlCompleteHandler});
xmlLoader.load();

function xmlCompleteHandler(event:LoaderEvent):void{
trace("XML loaded!");
var mainQueue = LoaderMax.getLoader("loaderQueue");
trace("What's in the mainQueue= " + mainQueue.content);
var swfArray = mainQueue.content;
trace("swfArray contains= " + swfArray);
for (var m:int = 0; m < swfArray.length; m++){
	mainHolder.addChild(swfArray[1]);
	swfArray[1].scaleX = swfArray[1].scaleY = 0.25;
       TweenLite.to(swfArray[1], 1, {alpha:1});
	}
var thumbArray = mainQueue.getChildren();
for (var t:int = 0; t < thumbArray.length; t++){
	if (thumbArray[t] is SWFLoader){
		var thumb:ContentDisplay = thumbArray[t].content;
		} 
	var thumbURLS = thumbArray[t].vars.thumb;
	trace(thumbURLS);
	}
mainQueue.load();
trace("children of XMLLoader " + event.target.getChildren().length);
}

 

Am I missing something that LoaderMax would do natively of do I need to come up with some kind of "stringArrayToObjectArray" and append it to my swfArray?

Thanks in advance as always

Karl

Link to comment
Share on other sites

i don't really understand the question.

 

i do see a potential problem:

 

var thumbArray = mainQueue.getChildren();

for (var t:int = 0; t

if (thumbArray[t] is SWFLoader){

var thumb:ContentDisplay = thumbArray[t].content;

}

var thumbURLS = thumbArray[t].vars.thumb;

trace(thumbURLS);

}

 

that line of code (in bold) is constantly overwriting the value of thumbURLS. when you are done with your loop, thumbURLS will only have one value (the last value set via the loop).

furthermore since you are declaring the var inside a loop inside a function, it will be impossible to access that value outside the function.

 

 

I'm guessing you want thumbURLS to be its own array of thumb url strings. outside of any functions declare:

 

var thumbURLS:Array =[]; 

 

 

 

inside your loop:

 

thumbURLS.push(thumbArray[t].vars.thumb)

 

also, each SWFLoader that is created will always know what it's vars.thumb is, I'm not so sure you need to pull that data out and store it somewhere else.

 

also important to note is that the contentDisplayObject (the sprite that contains your swf) of any loader stores a reference to it's own loader. so if you click on one of your swfs it is possible to figure out which loader loaded it, and in turn pull any vars associated with it:

 

http://www.greensock.com/as/docs/tween/ ... splay.html

A container for visual content that is loaded by any of the following: ImageLoaders, SWFLoaders, or VideoLoaders. It is essentially a Sprite that has a loader property for easily referencing the original loader, as well as several other useful properties for controling the placement of rawContent and the way it is scaled to fit (if at all). You can add a ContentDisplay to the display list or populate an array with as many as you want and then if you ever need to unload() the content or reload it or figure out its url, etc., you can reference your ContentDisplay's loader property like myContent.loader.url or (myContent.loader as SWFLoader).getClass("com.greensock.TweenLite");

Link to comment
Share on other sites

Thanks for your detailed answer Carl. I'm playing with different methods while learning and it seems I get into a corner & unable to express the correct terms.

When I trace mainQueue.content.length I get 4 as it's seeing "url" in the node and grabbing that as contentDisplayObject. Where I am getting lost is how to get the "thumb" displayed & usable for mouse events.

If I use mainQueue.getChildren() I get coercion errors.

 

I'm also not sure if I can add event listeners within this line. Haven't found that in the AS docs.

var mainQueue = LoaderMax.getLoader("loaderQueue");

 

Thanks for your help as I get my head wrapped around event triggered coding :)

Karl

Link to comment
Share on other sites

here is a little example that

 

-creates and loads an XMLLoader

-xml contains 3 swfLoaders

-3 swfs load

-each loaded swf is clickable

-each loaded swf when clicked will access the "description" attribute its SWFLoader node in the xml

 

XML






 

AS3

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.ContentDisplay;
import flash.events.MouseEvent;

LoaderMax.activate([sWFLoader]);

var xPos:Number = 0;

var queue:XMLLoader = new XMLLoader("data.xml",{onComplete:completeHandler,onChildComplete:swfCompleteHandler,maxConnections:1});

queue.load();

function completeHandler(e:LoaderEvent):void {
trace("xml and swfs loaded");
setUpEventListeners();
}


function swfCompleteHandler(e:LoaderEvent):void {
trace("this just loader just loaded " + e.target);
var swf:ContentDisplay = e.target.content as ContentDisplay;
swf.x = xPos;
addChild(swf);
xPos +=  100;
}

function setUpEventListeners() {
for each (var item in queue.getChildren()) {
	item.content.addEventListener(MouseEvent.CLICK, getInfo);
	item.content.buttonMode = true;
}

}

function getInfo(e:MouseEvent):void{
trace("\nmy Loader = " + e.currentTarget.loader);
trace("my description = " + e.currentTarget.loader.vars.description);

output_txt.text = e.currentTarget.loader.vars.description;

}

Link to comment
Share on other sites

No matter what I do I keep ending up with coercion errors. See, I have 2 url's in the same node, one is 'url=' the other is 'thumb=' and vars just grabs the string as far as I can tell. I think restructuring my thinking from the xml out is my best plan... Fun learning what I can & can't do though :D

Thanks again Carl

Karl

Link to comment
Share on other sites

yes, when your xml is parsed LoaderMax automatically sees url as the location of the swf it needs to load and it gets loaded.

 

thumb is just a string that you created as additional data that gets attached to each SWFLoader.

 

in my example I just illustrated how to access that string data.

if you want you can pass the vars.thumb string into a new SWFLoader.

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