PDA

View Full Version : function arguments?


moglie
08-01-2008, 07:37 AM
Take this example from the help files. How would I go about making the totalEntries variable an argument so I could keep this class "generic" and go about setting the totalEntries variable in the Flash file on frame 1?

package {
import fl.controls.TileList;
import fl.data.DataProvider;
import flash.display.Sprite;
import flash.events.Event;

public class MakeTileList extends Sprite {
public function MakeTileList() {
var dp:DataProvider = new DataProvider();
var totalEntries:uint = 5;
var i:uint;
for (i=0; i<totalEntries; i++) {
dp.addItem( { label:"star"+i, source:"slide" +i, scaleContent:false} );
}
var myTileList:TileList = new TileList();
myTileList.allowMultipleSelection = true;
myTileList.columnWidth = 125;
myTileList.rowHeight = 150;
myTileList.dataProvider = dp;
myTileList.columnCount = 3;
myTileList.rowCount = 1;
myTileList.move(10,10);
addChild(myTileList);
}
}
}

DiamondDog
08-01-2008, 09:50 AM
Try this:package {
import fl.controls.TileList;
import fl.data.DataProvider;
import flash.display.Sprite;
import flash.events.Event;

public class MakeTileList extends Sprite {

var totalEntries:uint; // declare 'totalEntries' here

public function MakeTileList(numberOfEntries:uint) { // constructor takes a uint argument

totalEntries = numberOfEntries; // grab the argument that was passed in

var dp:DataProvider = new DataProvider();
// var totalEntries:uint = 5; // don't need this now
var i:uint;
for (i=0; i<totalEntries; i++) {
dp.addItem( { label:"star"+i, source:"slide" +i, scaleContent:false} );
}
var myTileList:TileList = new TileList();
myTileList.allowMultipleSelection = true;
myTileList.columnWidth = 125;
myTileList.rowHeight = 150;
myTileList.dataProvider = dp;
myTileList.columnCount = 3;
myTileList.rowCount = 1;
myTileList.move(10,10);
addChild(myTileList);
}
}
}

moglie
08-01-2008, 01:19 PM
Maybe I"m passing the argument wrong or instantantiating the thing incorrectly. Trying doing it like this already but kept getting all kinds of errors. Wrote a simple class making a spectrum analyzer for this same application and passed arguments fine. But can't get it to work on the tile list.