PDA

View Full Version : Dynamic scrolling!


zartan917
02-18-2004, 04:35 PM
Hi again...
I have this flash map editor that creates an amount of tiles/boxes
with an input number. Does anyone know how to generate the
boxes at a fixed point...for instance if someone types in 40 boxes
I'd just want 10 across and 10 down (*sounds like a crossword)
to Show with the rest scrollable.....Does this make sense?? If it's
an easy line of code to put in please help! here is the sample code. thanks:
zartan917@aol.com

global constants
tileW = 30;
tileH = 30;
w = Number(inputWidth);
h = Number(inputHeight);

// default tile
default_tile = 0
// rect
rect = { top:0, left:20, right w*tileW)+20, bottom h*tileH), downfall:45 };

// sets up the grid + an empty array
function setUp () {
// create an empty array
level = new Array(h);
for ( var i=0; i < w; ++i ) {
level[i] = new Array(w);
}
// attach lines to create a grid
for ( var i=0; i<=h; ++i ) {
this.attachMovie("line", "line"+i, ++d);
this["line"+i]._width = rect.right-rect.left;
this["line"+i]._x = rect.left;
this["line"+i]._y = rect.downfall + (tileH*i);
for ( var j=0; j<=w; ++j ) {
this.attachMovie("line", "line"+i+"_"+j, ++d);
this["line"+i+"_"+j]._width = (tileH*h);
this["line"+i+"_"+j]._x = rect.left + (tileW*j);
this["line"+i+"_"+j]._y = rect.downfall;
this["line"+i+"_"+j]._rotation = 90;
}
}
type = default_tile;
}

// generates a string of of how the current array looks like
function generate () {
//output map
output = "map = [ ";
for (var i = 0; i<h; ++i) {
if (i == 0) {
output += "[";
} else {
output += " [";
}

for (var j = 0; j<w; ++j) {
if ( level[i][j] == null ) {
level[i][j] = default_tile;
}

output += level[i][j];

if (j == (w-1)) {
//HELLLLP RIGHT ABOUT HERE...
output += "";
} else {
output += ",";
}
}
if (i == (h-1)) {
output += "]";
} else {
output += "],\n";
}
}
output += " ];";
}

// attaches the tiles when drawn on the grid
function draw () {
var x = _root._xmouse;
var y = _root._ymouse;
var cx = Math.floor( (x-rect.left)/tileW );
var cy = Math.floor( (y-rect.downfall)/tileH );

if ( cx >= 0 && cx < w && cy >= 0 && cy < h ) {
if ( !Key.isDown(Key.SPACE) ) {
if ( this["t_"+cy+"_"+cx] ) {
removeMovieClip (this["t_"+cy+"_"+cx]);
}
this.attachMovie("tile", "t_"+cy+"_"+cx, ++d);
this["t_"+cy+"_"+cx]._x = rect.left + (tileW*cx);
this["t_"+cy+"_"+cx]._y = rect.downfall + (tileH*cy);
this["t_"+cy+"_"+cx].gotoAndStop ( type );
level[cy][cx] = type;
} else {
removeMovieClip ( this["t_"+cy+"_"+cx] );
level[cy][cx] = default_tile;
}
}
}

// updates the current-clip
function update () {
current.gotoAndStop (type);
}


setUp();