Dynamic buttons

After reading a tutorial on kirupa and aditional options at this forum, i wanted to make an image gallery were the number of buttons that apear changes as there are more or less images in the image directory.
So if i have 2 images, there should be 2 buttons.

I’ve tried this, but… it doesn’t work.

This is the code i used:

var sPlace:String = "images/";
lv = new LoadVars();
lv.onLoad = function(success) {
	if (success) {
		pArray = this.imgList.split(", ");
		for (var i = 0; i<pArray.length-1; i++) {
			_root.mcHolder.attachMovie("mcSquare", "mcSquare"+i, _root.getNextHighestDepth());
			_root.mcHolder._x += i*100;
	} else {
		info.text = "could not load file";

The result i get is that 1 button is displayed, altough he does the loop several times.

Best regards,
(first time poster, long time reader :thumb: )