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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load multiple jpegs from xml

Status
Not open for further replies.

fostom

Programmer
Jul 3, 2002
31
NO
Hi! Can anyone tell me how I can load multiple jpgs into a flash movie from a xml document? I need to create a movie clip on the fly.. well, this I have managed, but lets say I have 5 images I want to display from a xml doc at different positions in the movie. To create this I do a for-loop on all the images in the xml file and get the image file paths, then I create an unique filename (ex. var movieClipName:String = "newFileName" + j;) (j is the iterator in the for-loop), then I create a new movieclip (ex. _root.createEmptyMovieClip(movieClipName, j);

...here the problem starts.. you see, now I want to position the new movieClip. Ideally I would see this work: _root.movieClipName._x = 40 * j;
_root.movieClipName._y = 40 * j;
loadMovie(path, movieClipName);
...but this doesnt work. I cant find ANY way to position the new movie clip.

Does this make any sense? ANY IDEAS?

Regards, Tommy
 
What version of Flash are you using?

Wow JT that almost looked like you knew what you were doing!
 
I am using the newest version Flash MX 2004..
 
Any chance you are using Pro? I only ask because it is a bit easier with the XML connection components.

Wow JT that almost looked like you knew what you were doing!
 
Sorry, man.. I am in deed using Flash MX Pro 2004. But there is no problem with the xml feeding..
 
This works, adapted from your code but creating the instance names in a different way:

Code:
for (j=1; j<5; j++) {
	path = 'thumbs/thumb'+j+'.jpg';
	_root.createEmptyMovieClip('movieClip'+j, j);
	_root['movieClip'+j]._x = 40*j;
	_root['movieClip'+j]._y = 40*j;
	_root['movieClip'+j].loadMovie(path);
}

 
Thank you wangbar.. This was exactly what I was looking for. Works great! :)
 
btw.. do you know how I can add a drag and drop function to the newly created movieClips in the for-loop? I've tried a lot of things, but nothing seems to work.. :(
 
You can assign events like this:

Code:
_root['movieClip'+j].onPress = function() {
		this.startDrag();
	};
_root['movieClip'+j].onRelease = function() {
		this.stopDrag();
}
 
hmmm.. that does'nt seem to work..

this is a part of my code where I added your code.. it's just a for-loop which get images from a xml sheet and put them in rows 3 by 3.

.
.
for (j=0; j<articleTag.childNodes.length; j++)
{
//trace("inside main for-loop");
if (articleTag.childNodes[j].nodeName != null)
{
if (articleTag.childNodes[j].nodeName == "slideNode")
{
counter ++;
trace("main counter: " + counter);
link = articleTag.childNodes[j].firstChild.nodeValue;
getShit = articleTag.childNodes[j];
id = getShit.attributes["jpegURL"];
getHeight = getShit.attributes["height"];
getWidth = getShit.attributes["width"];
//trace(getHeight);
//trace(getWidth);
var setNewIterator:Number = j;

path = id;
_root.createEmptyMovieClip('image'+j, j);

if (counter == '1') {
_root['image'+j]._x = 0;
_root['image'+j]._y = 0;
trace("counter=1");
}
else {
//hvis bilde nr 3 så legg inn ny rad
if (counter == '4' || counter == '7' || counter == '10') {
internalCounterNewUniqueRow++;
internalCounter = 0;
internalCounterNewRow = 0;
var getHeightAndBugger:Number = Number(getHeight) + setBuffer;
var addHeight:Number = getHeightAndBugger * internalCounterNewUniqueRow;

_root['image'+j]._x = 0;
_root['image'+j]._y = addHeight;
trace("counter=4");
trace("counter=7");
flag = "NewRow";
}
else{
internalCounter++;
trace("internalCounter=" + internalCounter);
var getWidthAndBuffer:Number = Number(getWidth) + setBuffer;
var addWidth:Number = getWidthAndBuffer * internalCounter;
trace(addWidth);

if (flag == "NewRow"){
internalCounterNewRow++;
trace("internalCounterNewRow=" + internalCounterNewRow);
var getWidthAndBuffer2:Number = Number(getWidth) + setBuffer;
var addWidth2:Number = getWidthAndBuffer2 * internalCounterNewRow;
var getHeightAndBugger:Number = Number(getHeight) + setBuffer;
var addHeight:Number = getHeightAndBugger * internalCounterNewUniqueRow;
_root['image'+j]._x = addWidth2;
_root['image'+j]._y = addHeight;
}
else {
_root['image'+j]._x = addWidth;
_root['image'+j]._y = 0;
}

trace("counter>1");
}
}

_root['image'+j].loadMovie(path);

//the startDrag and stopDrag doesnt work..
_root['image'+j].onPress = function() {
this.startDrag();
};
_root['image'+j].onRelease = function() {
this.stopDrag();
};

if (counter == Number(articleTag.childNodes.length))
{counter=0;
internalCounter=1;
}
.
.

any idea?

Tommy
 
The code works okay on a standard movieclip like here:

Code:
for (var i = 0; i<5; i++) {
	var clip = this.attachMovie('clip', 'clip'+i, i, {_x:i*50, _y:0});
	this['clip'+i].onPress = function() {
		this.startDrag();
	};
	this['clip'+i].onRelease = function() {
		this.stopDrag();
	};
}

I think it may be down to the fact you're loading new content into the clip which is clearing the events you've just set up.

What you can do is to create another clip inside your clip and use that as the one that accepts the loaded image while the original clip is the one you attach the events to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top