PDA

View Full Version : [?] Manipulating loaded movieClips



decumbo
January 23rd, 2007, 12:53 PM
#include "config.txt"

var tTiles = terrainTiles; // from config.txt
var tPath = terrainPath; // from config.txt
var fType = FileType; // from config.txt

var selectedTile:String;

// loading stuff
function loadImages(imageNum, imageLocation, fileType) {
var imageList = Array();
var images:MovieClip = this.createEmptyMovieClip("images", this.getNextHighestDepth());
for (var i=1; i<= imageNum; ++i) {
imageList.push(imageLocation+i+fileType);
}
for (var i=1; i <= imageNum; ++i) {
images.createEmptyMovieClip("t"+i, i);
images["t"+i].createEmptyMovieClip("e"+i, i);
images["t"+i]["e"+i].loadMovie(imageList[i-1]);
images["t"+i]._alpha = 50;
images["t"+i].onRollOver = function() { this._alpha = 100; }
images["t"+i].onRollOut = function () { fadeOut(this); }
images["t"+i].onPress = function () { tileSelect(this); trace(selectedTile); }
}
return images;
}

var images:MovieClip = loadImages(tTiles, tPath, fType);

function tileSelect(tile) {
currentTileBox.removeMovieClip();
currentTileBox.duplicateMovieClip(images.tile, tile+"sel", currentTileBox.getNextHighestDepth());
currentTileBox.attachMovie(tile+"sel", "tile selection", currentTileBox.getNextHighestDepth(), {_width:2, _height:2});
selectedTile = tile._name;
}

I can trace the current selection no problem but the selected tile does not duplicate and embed itself into the currentTileBox. I know the problem lies within the tileSelect function. Perhaps scoping issue? Am I referring everything correctly?

If it aids at all, this is what I am working on:
http://www.student.cs.uwaterloo.ca/~bbobnis/

Thanks in advance,
decumbo

SacrificialLamb
January 23rd, 2007, 03:05 PM
most that code look's ok as long as all your linking is good (which is hard in a big app) but i don't know where you get "tile._name" from it look's like it should be the name of the tile you just made but dose not appear to be, but I don't know if that is a problem.
Have you tried?
tempName = currentTileBox.duplicateMovieClip(images.tile, tile+"sel", currentTileBox.getNextHighestDepth());
trace(TempName);
or tracing the attachMovie and tile._name to see that they are what thy should be if there at all.

Is this the only place where this problem could be coming from?

What exactly is the code not doing that is should
Also not really a problem but an idea you can change thing's like
images.createEmptyMovieClip("t"+i, i);
images["t"+i].createEmptyMovieClip("e"+i, i);
to
temp = images.createEmptyMovieClip("t"+i, i);
temp.createEmptyMovieClip("e"+i, i);
so temp is a var of the name of the created MC, it can make for faster coding and reduce the chance of linking problems.

I have had some completely unexplained linking problems before with flash where some thing was on _level0 (_root) but would not respond to its name that was the same as what it was tracing back to me with trace(this) so I had to use the name = attachMovie this.

decumbo
January 23rd, 2007, 11:56 PM
// loading stuff
function updateCurrentTileBox(tile) {
var bmp:BitmapData = new BitmapData(2, 2);
bmp.draw(tile);
currentTileBox.removeMovieClip(holder);
currentTileBox.createEmptyMovieClip("holder", currentTileBox.getNextHighestDepth());
currentTileBox.holder.attachBitmap(bmp, currentTileBox.getNextHighestDepth());
}

function loadImages(imageNum, imageLocation, fileType) {
var imageList = Array();
var images:MovieClip = this.createEmptyMovieClip("images", this.getNextHighestDepth());
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(this);
for (var i=1; i <= imageNum; ++i) {
imageList.push(imageLocation+i+fileType);
}
for (var i=1; i <= imageNum; ++i) {
images.createEmptyMovieClip("t"+i, i);
images["t"+i].createEmptyMovieClip("e"+i, i);
mcLoader.loadClip(imageList[i-1],images["t"+i]["e"+i]);

images["t"+i]._alpha = 50;
images["t"+i]._x = 16*(i-1);
images["t"+i].onRollOver = function() { this._alpha = 100; }
images["t"+i].onRollOut = function () { fadeOut(this); }
images["t"+i].onPress = function () {
selectedTile = this._name;
updateCurrentTileBox(this);
}
}
return images;
}