主题:  利用flashmx制作表格

金山羊

职务:普通成员
等级:4
金币:10.0
发贴:827
#12002/9/3 17:33:08
//定义画表格的类,并且声明它的属性,并给每个属性一个默认值
//类定义时有两个参数,一个用来指向操作的mc,另一个用来导入要显示的数据:
function Make_Table(c_this,c_data)
{
    //导入数据为类内部变量(此处为数组,如果改变则外部数组也改变,属于传递地址):
    this.data_text = c_data;
    //设置操作mc地址:
    this.MovieClip = c_this;
    //设置类的所有内部属性:
    this.row = this.data_text[0].length;
    this.column = this.data_text.length;
    this.text_width = 50;
    this.text_height = 18;
    this.start_x = 100;
    this.start_y = 50;
    this.bg_color = 0xffffff;
    this.text_color = 0;
    this.border_color = 0;
    this.text_selectable = true;
    this.text_align = "center";
    this.text_bold = false;
    this.text_italic = false;
    this.text_size = null
    this.text_underline = false;
}
//根据定义的参数与属性来显示表格
//一个参数用来传递返回深度,用来多次画表不会重复:
Make_Table.prototype.Draw_Table = function(c_deep)
{
    if(c_deep == undefined) c_deep = 0;
    for (var j = 0; j        for (var i = 0; i            var word_x = this.start_x + i * this.text_width;
            var word_y = this.start_y + j * this.text_height
            this.MovieClip.createTextField("word"+j+i+c_deep, c_deep + j*this.row+i,word_x ,word_y,this.text_width,this.text_height);
            this.MovieClip["word"+j+i+c_deep].border = true;
            this.MovieClip["word"+j+i+c_deep].background = true;
            this.MovieClip["word"+j+i+c_deep].borderColor = this.border_color;
            this.MovieClip["word"+j+i+c_deep].backgroundColor = this.bg_color;
            this.MovieClip["word"+j+i+c_deep].textColor = this.text_color;
            this.MovieClip["word"+j+i+c_deep].selectable = this.text_selectable;
            this.MovieClip["word"+j+i+c_deep].text = this.data_text[j][i];
            //defined a format
            var this_word_format = new TextFormat();
            this_word_format.align = this.text_align;
            this_word_format.bold = this.text_bold;
            this_word_format.italic = this.text_italic;
            this_word_format.size = this.text_size;
            this_word_format.underline = this.text_underline;
            this.MovieClip["word"+j+i+c_deep].setTextFormat(this_word_format);
        }
    }
    return c_deep + this.row * this.column;
};
//定义二维数组来存放数据(适合从数据库表中导入的数据):
//myData = [[1,1,1,1,1], [1,1,1,1,1], [1,1,1,1,1], [1,1,1,1,1], [1,1,1,1,1]];
myData = new Array(5);
for(var i = 0;i < myData.length;i++)
{
    myData[i] = new Array(5);
    for(var j = 0;j < myData[i].length;j++)
    {
        myData[i][j] = "你好";
    }
}
//定义一张新表,并改变它内部的默认属性:
myTable = new Make_Table(this,myData);
myTable.text_width = 90;
//myTable.text_height = 20;
myTable.start_x = 50;
myTable.bg_color = 0xffffee;
myTable.text_color = 0xff0000;
myTable.border_color = 0x0000ff;
//myTable.text_align = "left";
//myTable.text_size = 15;
myTable.text_italic = true;
myTable.text_bold = true;
myTable.text_underline = true;
myTable.text_selectable = false;
now_deep = myTable.Draw_Table();
//再定义一张表,让其与第一张表连接起来:
myTable1 = new Make_Table(this,myData);
myTable1.start_x = myTable.start_x;
myTable1.text_width = myTable.text_width;
myTable1.start_y = myTable.start_y + myTable.column * myTable.text_height;
now_deep = myTable1.Draw_Table(now_deep);
//本例子利用FlashMx在文本框方面的新功能来画表格,并显示数据
//本例子适合在flash中来动态显示数据库表中的数据,只要将数据库表中的数据读入flash后转换为数组即可使用
//本实例利用简单,并且容易扩展功能,容易修改后自己利用
//因为时间仓卒,可能还有很大的漏洞,另外也可能有照顾不周全与不合理的地方,希望众闪客多提意见
//作者:goldgoat
//时间:2002.9.3
//事件:作者在苦学jsp与数据库时......


5d.cn
FLASHDEP
TECHNOLOGY SUPPORT
JAVA/ACTIONSCRIPT/javascript
CFML/JSP/COLDFUSION/FLASH REMOTING
JRUN/COLDFUSIONMX
FLASH/DREAMWEARER

Mozier

职务:管理员
等级:5
金币:11.0
发贴:2994
#22002/9/5 13:43:52
好东东,要置顶!
UP~~~



5D公害

职务:普通成员
等级:9
金币:10.3
发贴:36272
#32002/9/5 14:25:21
可以加入精华了



金山羊

职务:普通成员
等级:4
金币:10.0
发贴:827
#42002/9/6 7:56:10
//昨天在应用的时候发现了一些问题
//比如行和列的定义是反的
//也由此想到应该行和列应该是灵活的才行,于是做了修改,新的程序如下
//另外要想显示汉字要加上下面一句:
System.useCodepage=true;
//定义画表格的类,并且声明它的属性,并给每个属性一个默认值
//类定义时有两个参数,一个用来指向操作的mc,另一个用来导入要显示的数据:
function Make_Table(c_this,c_data)
{
//导入数据为类内部变量(此处为数组,如果改变则外部数组也改变,属于传递地址):
this.data_text = c_data;
//设置操作mc地址:
this.MovieClip = c_this;
//设置类的所有内部属性:
this.row = this.data_text.length;
this.column = this.data_text[0].length;
this.text_width = 50;
this.text_height = 18;
this.start_x = 100;
this.start_y = 50;
this.bg_color = 0xffffff;
this.text_color = 0;
this.border_color = 0;
this.text_selectable = true;
this.text_align = "center";
this.text_bold = false;
this.text_italic = false;
this.text_size = null
this.text_underline = false;
}
//根据定义的参数与属性来显示表格
//一个参数用来传递返回深度,用来多次画表不会重复:
//参数c_change用来调换行和列的位置,c_change为1怎行列调换
Make_Table.prototype.Draw_Table = function(c_deep,c_change)
{
if(c_deep == undefined) c_deep = 0;
if(c_change == 1)
{
this.real_row = this.column;
this.real_column = this.row;
}else{
this.real_row = this.row;
this.real_column = this.column;
}
for (var j = 0; j for (var i = 0; i var word_x = this.start_x + i * this.text_width;
var word_y = this.start_y + j * this.text_height
this.MovieClip.createTextField("word"+j+i+c_deep, c_deep + j*this.real_column+i,word_x ,word_y,this.text_width,this.text_height);
this.MovieClip["word"+j+i+c_deep].border = true;
this.MovieClip["word"+j+i+c_deep].background = true;
this.MovieClip["word"+j+i+c_deep].borderColor = this.border_color;
this.MovieClip["word"+j+i+c_deep].backgroundColor = this.bg_color;
this.MovieClip["word"+j+i+c_deep].textColor = this.text_color;
this.MovieClip["word"+j+i+c_deep].selectable = this.text_selectable;
this.MovieClip["word"+j+i+c_deep].text = (c_change == 1)?Del_inString(this.data_text[i][j]," "):Del_inString(this.data_text[j][i]," ");
//defined a format
var this_word_format = new TextFormat();
this_word_format.align = this.text_align;
this_word_format.bold = this.text_bold;
this_word_format.italic = this.text_italic;
this_word_format.size = this.text_size;
this_word_format.underline = this.text_underline;
this.MovieClip["word"+j+i+c_deep].setTextFormat(this_word_format);
}
}
return c_deep + this.row * this.column;
};


5d.cn
FLASHDEP
TECHNOLOGY SUPPORT
JAVA/ACTIONSCRIPT/javascript
CFML/JSP/COLDFUSION/FLASH REMOTING
JRUN/COLDFUSIONMX
FLASH/DREAMWEARER

janlay

职务:管理员
等级:7
金币:28.0
发贴:7244
#52002/9/8 17:46:36
引用:
this.MovieClip["word"+j+i+c_deep].border = true;

如果i or j可以达到2位数或更高,可能会产生不可预料的结果,我想可以通过在高位补零的办法来解决。



金山羊

职务:普通成员
等级:4
金币:10.0
发贴:827
#62002/9/9 12:38:25
我昨天做东西的时候遇到了这个问题,可以让i与j不从0开始循环,而从10或者更大来解决就没问题了


5d.cn
FLASHDEP
TECHNOLOGY SUPPORT
JAVA/ACTIONSCRIPT/javascript
CFML/JSP/COLDFUSION/FLASH REMOTING
JRUN/COLDFUSIONMX
FLASH/DREAMWEARER

janlay

职务:管理员
等级:7
金币:28.0
发贴:7244
#72002/9/11 21:39:26
可是如果超过 3 位数呢?为了追求完美,别骂我纠缠不休



金山羊

职务:普通成员
等级:4
金币:10.0
发贴:827
#82002/9/12 7:56:51
当然实际中我并没有采用我说的办法,我利用二维转一维的办法,不用i+j而是利用(i*column + j)返回一个值来代替两个值
不过话说回来了,要一个表格超过两位数,也真是不小这个表格

我现在遇到了flash上的类似的问题,flash函数递归只能有255次,如果多了就报错不执行了,这个非常限制我的制作,请问janlay兄有什么解决的办法没有?(不要间接的,要直接的)


5d.cn
FLASHDEP
TECHNOLOGY SUPPORT
JAVA/ACTIONSCRIPT/javascript
CFML/JSP/COLDFUSION/FLASH REMOTING
JRUN/COLDFUSIONMX
FLASH/DREAMWEARER

flashfun

职务:普通成员
等级:1
金币:0.0
发贴:65
#92002/9/12 8:03:10
引用:
本例子适合在flash中来动态显示数据库表中的数据,只要将数据库表中的数据读入flash后转换为数组即可使用...
求教goldgoat大虾,能否解决这个问题:
"前台是flash,后台是asp,flash中有数组a1[],asp中有数组a2(),因为其数组的括号是不一致的,一个是[],另一个是(),asp中的数组已读入flash中,并能在flash的动态文本中显示.但无法转换为数组.所以现在问题是:在flash中如何进行计算,如( test=a1[1]+a2(1) )"
后来网友认为应通过字符串来联系的,再转成数组,因此就带来下面的问题:
如何在flash的actionscript中做到:
for (i=1;i<100;i++) {
a[i]=360-bb
}
其中bb为b1.....b100,那么bb应如何写, 多谢帮助!!!



金山羊

职务:普通成员
等级:4
金币:10.0
发贴:827
#102002/9/12 12:31:13
由后台转入flash的数据一定是字符串,这样将数组中的每一个元素按照一定规则划分开(比如用 , 格开),然后在flash里面用string函数split语句将整个字符串按照划分规则转换为数组,这样就可以了

另外for循环可以写成这样就解决你的第二个问题:
for (i=1;i<100;i++) {
a[i]=360-this["b" + i];
//a[i] = 360 - eval("b" + i);
}


5d.cn
FLASHDEP
TECHNOLOGY SUPPORT
JAVA/ACTIONSCRIPT/javascript
CFML/JSP/COLDFUSION/FLASH REMOTING
JRUN/COLDFUSIONMX
FLASH/DREAMWEARER

flashfun

职务:普通成员
等级:1
金币:0.0
发贴:65
#112002/9/12 16:24:47
非常感谢goldgoat的帮助,第一方法能否给出范例来,帮助理解.
在第二个方法中,b1,b2,b3..b100是通过loadvariablesnum("mydata.asp","","POST");//output--->b1=12&b2=34...&b100,然而此数据只能在flash的动态文本中显示.但无法转换为数组(用您的方法,我不知何故),请goldgoat再次指点,多谢!!!



金山羊

职务:普通成员
等级:4
金币:10.0
发贴:827
#122002/9/13 12:40:51
在你的asp里不用输出&b1=12&b2=34...而输出b=12,34,56...
这样到Flash里面就可以利用字符串函数split函数将b字符串转换为一个数组格式如下:
b_Array = b.split(",");


5d.cn
FLASHDEP
TECHNOLOGY SUPPORT
JAVA/ACTIONSCRIPT/javascript
CFML/JSP/COLDFUSION/FLASH REMOTING
JRUN/COLDFUSIONMX
FLASH/DREAMWEARER