Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i put this movieclip into a scrollpane?

Status
Not open for further replies.

natg504

MIS
Dec 5, 2005
13
US
I'm trying to load some .swf files into my Flash project from XML. I've attached my code below. "pane" is a scrollpane component on the stage, and "emptyMC" is an empty movie symbol in the library.

Everything is working fine... I have the images loading in rows, 18 per row, but if there's a large number of images, I want to be able to scroll through them. So, after all the images are loaded, I want to put them all into a scrollpane component. I just don't know how to attach the dynamically created movieclip with all the images to the scrollpane.

Any ideas would really be appreciated!!

thanks,

stop();
StencilGalleryXML = new XML();
StencilGalleryXML.onLoad = init;
StencilGalleryXML.load("stencils.xml");
StencilGalleryXML.ignoreWhite = true;

var xPos:Number = 185;
var yPos:Number = 315;
var MCL = new MovieClipLoader();

function init(success) {
if (success == true) {
rootNode = StencilGalleryXML.firstChild;
nbrStencils = rootNode.childNodes.length;
currentStencil = rootNode.firstChild;
_root.pane.contentPath = "emptyMC";
_root.pane.vScrollPolicy = "on";

for (i=0; i<nbrStencils; i++) {
mcName = "stencil"+i;
loadImage(currentStencil.attributes.swfURL, currentStencil.attributes.outline, mcName, currentStencil.firstChild.nodeValue, i+1);
currentStencil = currentStencil.nextSibling;
}

//CAN I ADD THE PARENT MOVIE CLIP TO THE pane SCROLLPANE COMPONENT HERE???
//p = pane.content.attachMovie("emptyMC", "scrollingMovie", this.getNextHighestDepth());
//p.loadMovie()
}
}

function loadImage(imgSrc, imgOutline, clipName, desc, ctr) {
//Creates a parent movie clip to hold the container
this.createEmptyMovieClip("parent", this.getNextHighestDepth());
newClip = parent.createEmptyMovieClip(clipName, this.getNextHighestDepth());
//this is the movie clip the currentStencil will replace
newClip.createEmptyMovieClip("container_mc", this.getNextHighestDepth());
//use moviecliploader to load the currentStencil
MCL.loadClip(imgSrc, newClip.container_mc);

newClip._y = yPos;
newClip._x = xPos;

//new row after every 18 stencils
if (ctr%18 == 0) {
xPos = 185;
yPos += 30;
} else {
xPos += 30;
}
}

MCL.onLoadInit = function (targetMC) {
targetMC._width = 25;
targetMC._height = 25;
}

 
I've loaded dynamic content before using myScrollPane.content.attachMovie(...). The only key to that is invalidating the scrollpane so it will redraw itself. Just a simple myScrollPane.invalidate() after your scroll content has changed will do the trick.

Seems like there were a few other issues I encountered such as text fields.. make sure you are embeding the fonts for any text fields that may be in the scroller or else they won't show through the mask.

-Dustin
Rom 8:28
 
Hi Dustin,

Thanks for the response. I've tried using the content.attachMovie function, but nothing seems to show up. Am i referring to the movie incorrectly? I dont' really know if i should be attaching "parent" or "emptyMC" or what... I commented out the code i was trying to use to do that. It was:

//p = pane.content.attachMovie("emptyMC", "scrollingMovie", this.getNextHighestDepth());
//p.loadMovie()


thanks!
 
Well, looking over it again, it looks like it may just be a matter of not referencing the clips right. For enstance.. pane.content probably won't work.. try referencing it with _root.pane.content. A good way to test this is by tracing your variables.. trace(pane) should show you something like "level0.pane".. if it cant find it, you just get undefined.

I'm posting an example of one I did a while back. I actually just used a class for my movieclip that contained the ScrollPane. The scrollpane was named Container.

Code:
class ProductContainer extends MovieClip {
	var CurrentProduct:Product;
	var Container:ScrollPane;
	var CloseButton:MovieClip;
	var AlreadyLoaded = true;
	var ProductMovie:MovieClip;
	
	function ProductContainer() {
		this.CloseButton.onRelease = function() {
			this._parent.hideContainer();
		}
	}
	
	function loadProduct(myProduct:Product) {
		this.CurrentProduct = myProduct;
		this.ProductMovie = new MovieClip();
		this.ProductMovie = this.Container.content.attachMovie("ProductWithPic","ProdCont",this.getNextHighestDepth());
		var curPic = this.ProductMovie.attachMovie("PicHolder","ProdPic",this.ProductMovie.getNextHighestDepth());
		curPic.loadPicture("ProductFiles/" + this.CurrentProduct.PictureName);
		this.ProductMovie.txtName.text = this.CurrentProduct.Name;		
		this.Container.invalidate();
	}
	
	function hideContainer() {
		this._alpha = 0;
		this.ProductMovie.unloadMovie();
	}
	
	function showContainer() {
		this._alpha = 93;
		this.visible = true;
	}
}

-Dustin
Rom 8:28
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top