Jump to content
Search Community

Child index

ShortBus test
Moderator Tag

Recommended Posts

Hello all-

 

I've a situation where I'm loading 4 swfs into a movie clip. They load in as

product1

product2

product3

product4

Where product 4 is topmost & visible.

I'm trying to swap or set child indexes so product1 is topmost at initial load and I'm failing miserably. The following don't work, product4 always comes to the top.

var product1 = mainHolder.getChildAt(0);
var product4 = mainHolder.getChildAt(3);
mainHolder.swapChildren(product1,product4);

mainHolder.swapChildrenAt(0,numChildren -1);

var product1 = mainHolder.getChildAt(0);
mainHolder.setChildIndex(product1,mainHolder.numChildren -1);

 

Any thoughts on the matter are appreciated

Thanks

Karl

Link to comment
Share on other sites

How are you adding them in the first place? Are you just setting a "container" property in the ImageLoader?

 

Remember, one of the nice conveniences of LoaderMax is that it'll immediately create a ContentDisplay Sprite for each SWFLoader, ImageLoader, and VideoLoader, meaning you can put that container object wherever the heck you want even before you load() the content. If you addChild() the ContentDisplay, that object will rise to the top. So, for example:

 

mainHolder.addChild( myImageLoader1.content );

 

Even if the object is already a child of the mainHolder, it's fine - addChild() will make it go to the top of the list.

 

Does that help?

 

There are, of course, other ways to accomplish this but I didn't want to list them all here - I figured the addChild() would be simplest.

 

Also for the record, you could just change the order in which you create your ImageLoaders (assuming you're defining a "container" for each) because the ContentDisplay object gets added to the display list immediately when the instance is created. So if you want the stacking order to be 4, 3, 2, 1, (with 1 on top) you'd do:

 

var l4:ImageLoader = new ImageLoader("4.jpg", {container:mainHolder});
var l3:ImageLoader = new ImageLoader("3.jpg", {container:mainHolder});
var l2:ImageLoader = new ImageLoader("2.jpg", {container:mainHolder});
var l1:ImageLoader = new ImageLoader("1.jpg", {container:mainHolder});

 

Does that help?

Link to comment
Share on other sites

Hi Carl, good chatting with you again ;)

 

I am just using a container and all 4 swfs are dumping into it. I intent on loading all images(there will never be more than 4-6) for this project to have instant viewing from thumb clicks. Here's my xmlCompleteHandler:

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

function xmlCompleteHandler(event:LoaderEvent):void{
trace("XML loaded!");
var xml = xmlLoader.content;
var xmlList = new XMLList(xml.mov);
	trace("The xmlList= " + xml);
var mainLoader = new LoaderMax({name:"mainLoader",
									 maxConnections:1,
									 onProgress:progressHandler,
									 onComplete:mainCompleteHandler});
for (var i:int = 0; i < xmlList.length(); i++){
	var movLoader:SWFLoader = new SWFLoader("assets/products/" + xmlList[i].@url,
											new SWFLoaderVars()
											.name(xmlList[i].@name)
											.container(mainHolder)
											.scaleX(.25)
											.scaleY(.25)
											//.alpha(0)
											)
	mainLoader.append(movLoader);
};
mainLoader.load();
}

 

There is another similar for loading thumbs...

You'll notice I had an alpha property in there and until now I was changing alpha to 1 in a following handler with

TweenMax.to(mainHolder.getChildAt(0), .75, {alpha:1});

 

That all worked fine until I moved to the "click to magnify" part of the project and product1(child 0), even though showing, wasn't the event target. See where I'm going with this?

Does the way I'm doing it mean loader0 has all display objects and that's why I'm have a hard time with it?

Thanks again

Karl

Link to comment
Share on other sites

I hung with you until the last paragraph or so. You mention loader0 which I don't see in your code. I also don't see any "click to magnify" stuff or related code which is where you say the problem is. I'm at a loss to help without that. As far as the event target not being what you thought it should be, maybe you have an invisible object in front of the one you see? So the click is actually on the invisible DisplayObject? I dunno - again, I'm working kinda blind here. Feel free to post a super simple example FLA (and support files) that clearly demonstrates the issue. Please don't post your production files because those probably have a bunch of extra, non-essential code that would slow down troubleshooting.

 

It definitely sounds like the issue is unrelated to LoaderMax or any GreenSock tools, but hopefully we can get you some help.

Link to comment
Share on other sites

Hi Jack, thanks for all the GS goodies :D

The "loader0" was just a reference as I am assuming my SWFLoader w/ loop is putting it all in one place.

I'm trimming the fat for something to post, I'm sure y'all don't need 160+ lines. I pretty new to ECMAScript so it gets ugly...

Post the fla shortly

K

Link to comment
Share on other sites

I got ahead of myself... you are exactly right, it's an invisible object. That's where I was heading in the first place, I was looking to swap children so I'm not having this issue.

I can't trim it down much more than this to show the issue, but overall it's not terribly long.

The alpha property at line 38 is what I'd like to avoid

The mouse event handlers just drag for simplicity

Link to comment
Share on other sites

In trying to work with what I've shown ya I think I came to the conclusion I should maybe switch to basing my project on sprites and see about loaded each object into it's own sprite. Seems like I'll have more control that way and I'm going to probably be needing to setup some sprite layers for masking in the magnify segment of the project.

 

If anyone thinks of an idea for what I already have, please let me know.

Thanks

Karl

Link to comment
Share on other sites

No no, you definitely don't need to create a Sprite for each one - that's EXACTLY what LoaderMax already does for you. That's what the ContentDisplay objects are.

 

All you need to do is add this to the end of your xmlCompleteHandler() method (inside of it):

var loaders:Array = mainLoader.getChildren();
i = loaders.length; 
while (--i > -1) {
mainHolder.addChild(loaders[i].content);
}

 

That simply loops backwards through the array of loaders that you just dumped into the LoaderMax instance and puts them in the display list in the correct order. Another solution would be to reverse the order in which you create your SWFLoaders (as mentioned earlier).

 

I'm curious why you set the LoaderMax's maxConnections to 1. That'll load things sequentially, but you're waiting for all of them to load anyway and you can make better use of the bandwidth if you leave the maxConnections at 2 or even 3.

 

Also, you don't need to separate things so much in terms of waiting for all the big versions to load....then analyze the XML again and create another LoaderMax for all the thumbnails and wait for those...then after that add the MouseEvent listeners, etc. You can do all that as soon as the XML loads. Remember, the ContentDisplay is created IMMEDIATELY, so you can attach listeners, move it around in the display list, or whatever...even before loading begins. So I'd loop through the XML once and create the big loaders and the thumbnail loaders in one fell swoop, and also add the MouseEvent listeners. It'll consolidate your code and maybe improve performance a bit. Just a thought. Not necessary.

 

Hope that helps.

Link to comment
Share on other sites

Hi Jack, thanks for the patients & insight.

I had read in posts & the ASDocs about ContentDisplay objects but I guess it wasn't really sinking in that they Are actually Sprites. I guess with my limited (but growing) knowledge of tracing and troubleshooting, if I didn't see the words "object Sprite" returned I assumed it was something else. I guess with so many years in hardware & networking I have some blinders on regarding coding :roll: Thanks for the loop suggestion, I'll be putting that to use today over coffee & Mt Dew sessions.

 

I've had the maxConnections set from 1 to 4 throughout testing, not long before canning that sample it was 2. There again, I've been tweaking things every which way to see what happens during my learning & development. Making better use of the bandwidth is definitely something I can get behind and the main reason I got so interested in GS in the first place. I'm certainly glad that the buddy that I'm doing the site for has patients. I told him we could set him up like the big manufacturers so he could increase his sales, then found out how they do it wasn't cheap & easy, LOL. But then again I'm doing it pro bono so I'm learning on my dime.

 

The separation thing has been bugging be. I figured I needed to create an array of sorts to reference but haven't gotten that far.

I'm curious about implementing listeners. When I've been building "Lego style" like I have I sometimes feel I need multiple "onComplete" listeners to point to different functions. Is this just my lack of consolidation (e.g.: experience) or are their times this is viable?

 

Thanks again for the in depth response and I'll be digging in hard today.

Kind regards

Karl

Link to comment
Share on other sites

  • 2 weeks later...

First, thanks for all the advice I've gotten here, y'all are great!

I had to take some time off from this project to work on other things, thus the delay.

I've got everything loading at once now and have an array which is all looking great. I've just one movieclip and all the objects are located during the load making things simple there. Now I'm uncertain how to address manipulating specific items with the array. I've searched all over but nothing seems to address my specific circumstance. If I setup a for statement in my complete handler to trace what I've got in the array

for (var i:int = 0; i < pntLoaders.length; i++){
	var pntLoadersContent:String = pntLoaders[i].valueOf();
	trace("The pntLoaders array content is= " + pntLoadersContent);
}

 

I see (with the .name var commented out in my loaders)

The pntLoaders array content is= SWFLoader 'loader1' (assets/products/product1.swf)
The pntLoaders array content is= SWFLoader 'loader2' (assets/products/product2.swf)
The pntLoaders array content is= SWFLoader 'loader3' (assets/products/product3.swf)
The pntLoaders array content is= SWFLoader 'loader4' (assets/products/product4.swf)
The pntLoaders array content is= SWFLoader 'loader5' (assets/thumbnails/th_product1.swf)
The pntLoaders array content is= SWFLoader 'loader6' (assets/thumbnails/th_product2.swf)
The pntLoaders array content is= SWFLoader 'loader7' (assets/thumbnails/th_product3.swf)
The pntLoaders array content is= SWFLoader 'loader8' (assets/thumbnails/th_product4.swf)

 

I'm at a loss as to access either the loader# or the url so I can assign mouse events & such. I was looking for something like matching

"assets/thumbnails/th_product" + (i + 1) + ".swf"

after parsing the array but I was getting no where...

Maybe taking a break from the project wasn't good for my brain...

 

Any help is appreciated

Thanks

K

Link to comment
Share on other sites

I'm not sure this is exactly what you were asking, but might it be as simple as:

 

for (var i:int = 0; i     var cd:ContentDisplay = pntLoaders[i].content;
   cd.addEventListener(MouseEvent.CLICK, myFunction);
}
...

 

And by the way, if you want to get the ContentDisplay associated with a particular URL, you can do something like this anytime (after creating the loader of course):

LoaderMax.getContent("assets/thumbnails/th_product" + (i + 1) + ".swf");

 

Does that help?

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