-
How to change the color of a cell of the table
hello all
I created a table how can I write inside these cells and how it is possible to change the color of a specific cell if some condition is met, for example if the writing is excellent, the cell color is red
PHP Code:
onFrame (1) {
function mySquare (x:Number, y:Number, size:Number):MovieClip {
var depth:Number = _root.getNextHighestDepth( );
var square:MovieClip =_root.createEmptyMovieClip("example", depth);
square.beginFill(0x0022CC, 80);
square.lineStyle(2, 0xFF9900, 100);
square.moveTo(0, 0);
square.lineTo(size, 0);
square.lineTo(size, size);
square.lineTo(0, size);
square.lineTo(0, 0);
square.endFill( );
square._x = x;
square._y = y;
return square;
}
var size = 30;
for (i=0; i<10; i++) {
for (j=0; j<10; j++) {
var x_coord = i * (size + 5);
var y_coord = j * (size + 5);
var tempSquare:MovieClip =mySquare(x_coord+100, y_coord+10, size);
}
}
}
-
Client Software Programmer
I made you a function to store the cells in an object, and than to change cell 0,0 to red you use,
PHP Code:
setPixel(0,0,0x990000)
full script:
PHP Code:
var mc_obj={};
function mySquare (x:Number, y:Number, size:Number):MovieClip {
var depth:Number = _root.getNextHighestDepth( );
var square:MovieClip =_root.createEmptyMovieClip("example", depth);
square.beginFill(0x0022CC, 80);
square.lineStyle(2, 0xFF9900, 100);
square.moveTo(0, 0);
square.lineTo(size, 0);
square.lineTo(size, size);
square.lineTo(0, size);
square.lineTo(0, 0);
square.endFill( );
square._x = x;
square._y = y;
return square;
}
var size = 30;
for (i=0; i<10; i++) {
for (j=0; j<10; j++) {
var x_coord = i * (size + 5);
var y_coord = j * (size + 5);
var tempSquare:MovieClip =mySquare(x_coord+100, y_coord+10, size);
mc_obj["square_"+i+"_"+j]=tempSquare
}
}
setPixel(0,0,0x990000)
setPixel(5,5,0x00FF00)
function setPixel(x,y,color){
mc_obj["square_"+x+"_"+y].clear();
mc_obj["square_"+x+"_"+y].beginFill(color, 80);
mc_obj["square_"+x+"_"+y].lineStyle(2, 0xFF9900, 100);
mc_obj["square_"+x+"_"+y].moveTo(0, 0);
mc_obj["square_"+x+"_"+y].lineTo(size, 0);
mc_obj["square_"+x+"_"+y].lineTo(size, size);
mc_obj["square_"+x+"_"+y].lineTo(0, size);
mc_obj["square_"+x+"_"+y].lineTo(0, 0);
mc_obj["square_"+x+"_"+y].endFill( );
}
----------------------------------------------------------------------------------------------------------------------------------------
example 2:
PHP Code:
var mc_obj={};
function mySquare (x:Number, y:Number, size:Number):MovieClip {
var depth:Number = _root.getNextHighestDepth( );
var square:MovieClip =_root.createEmptyMovieClip("example", depth);
square.beginFill(0x0022CC, 80);
square.lineStyle(2, 0xFF9900, 100);
square.moveTo(0, 0);
square.lineTo(size, 0);
square.lineTo(size, size);
square.lineTo(0, size);
square.lineTo(0, 0);
square.endFill( );
square._x = x;
square._y = y;
return square;
}
var size = 30;
for (i=0; i<10; i++) {
for (j=0; j<10; j++) {
var x_coord = i * (size + 5);
var y_coord = j * (size + 5);
var tempSquare:MovieClip =mySquare(x_coord+100, y_coord+10, size);
mc_obj["square_"+i+"_"+j]=tempSquare
}
}
var num=0
onEnterFrame=function(){
for (i=0; i<10; i++) {
for (j=0; j<10; j++) {
setPixel(i,j,num);
num++
}
}
}
function setPixel(x,y,color){
mc_obj["square_"+x+"_"+y].clear();
mc_obj["square_"+x+"_"+y].beginFill(color, 80);
mc_obj["square_"+x+"_"+y].lineStyle(2, 0xFF9900, 100);
mc_obj["square_"+x+"_"+y].moveTo(0, 0);
mc_obj["square_"+x+"_"+y].lineTo(size, 0);
mc_obj["square_"+x+"_"+y].lineTo(size, size);
mc_obj["square_"+x+"_"+y].lineTo(0, size);
mc_obj["square_"+x+"_"+y].lineTo(0, 0);
mc_obj["square_"+x+"_"+y].endFill( );
}
Last edited by AS3.0; 09-18-2020 at 12:37 PM.
-
thaaaaaaaaaaaaaaank yoooooooooooooooou
how can i write into cells
-
Client Software Programmer
the condition in the setpixel function: if the text field says 1_1 the color will be red.
PHP Code:
var mc_obj={};
function mySquare (x:Number, y:Number, size:Number):MovieClip {
var depth:Number = _root.getNextHighestDepth();
var square:MovieClip =_root.createEmptyMovieClip("example",depth);
square.beginFill(0x0022CC, 80);
square.lineStyle(2, 0xFF9900, 100);
square.moveTo(0, 0);
square.lineTo(size, 0);
square.lineTo(size, size);
square.lineTo(0, size);
square.lineTo(0, 0);
square.endFill( );
square._x = x;
square._y = y;
return square;
}
var size = 30;
for (var j=1; j<10; j++) {
for (var i=1; i<10; i++) {
var x_coord = i * (size + 5);
var y_coord = j * (size + 5);
var tempSquare:MovieClip =mySquare(x_coord+100, y_coord+10, size);
tempSquare.createTextField("data_field", i*j+i+j,size/2-data_field.textWidth/1.6, size/2-data_field.textHeight/1.6, data_field.textWidth*2, data_field.textHeight*2,100);
data_field = tempSquare["data_field"]
data_field.selectable=false
data_field.getNextHighestDepth()
mc_obj["square_"+i+"_"+j]=tempSquare
data_field.text = i+"_"+j;
if(i==1&&j==1){
tempSquare.createTextField("data_field", this.getNextHighestDepth(),size/2-data_field.textWidth/1.6, size/2-data_field.textHeight/1.6, data_field.textWidth*2, data_field.textHeight*2,100);
mc_obj["square_"+1+"_"+1]["data_field"].text=1+"_"+1
}
}
}
setPixel(1,1,0x0022CC)
function setPixel(x,y,color){
if(mc_obj["square_"+x+"_"+y]["data_field"].text=="1_1"){
color=0x990000;
}
mc_obj["square_"+x+"_"+y].clear();
mc_obj["square_"+x+"_"+y].beginFill(color, 80);
mc_obj["square_"+x+"_"+y].lineStyle(2, 0xFF9900, 100);
mc_obj["square_"+x+"_"+y].moveTo(0, 0);
mc_obj["square_"+x+"_"+y].lineTo(size, 0);
mc_obj["square_"+x+"_"+y].lineTo(size, size);
mc_obj["square_"+x+"_"+y].lineTo(0, size);
mc_obj["square_"+x+"_"+y].lineTo(0, 0);
mc_obj["square_"+x+"_"+y].endFill( );
}
Last edited by AS3.0; 09-19-2020 at 12:19 AM.
-
can you load string data from txt file into cells
thanks and respect
-
Client Software Programmer
Depends, does the textfile come from local or from a website.
If it is local you can keep an as3 server running to get the data. If you have a website, you can use php to give it the file data.
-
local in the same folder to run from desktop
Last edited by kofa; 09-19-2020 at 12:17 PM.
-
Client Software Programmer
as2.xml:
PHP Code:
<0>@name=kofa@job=doctor@slary=5000</0>
<0>@name=alloy bacon@job=programmer@slary=personal</0>
full as2 script:
PHP Code:
var xmlFile = new XML();
xmlFile.onLoad = xmlLoaded;
xmlFile.ignoreWhite = true;
var xml_array=[]
function xmlLoaded(a){
if(a){
for(a=0;a<this.childNodes.length;a++){
text_array[a].text=this.childNodes[a].toString().split("<0>")[1].split("</0>")[0]
//trace(this.childNodes[a].toString().split("<0>")[1].split("</0>")[0].split("@")[1].split("=")[0])//name variable
//trace(this.childNodes[a].toString().split("<0>")[1].split("</0>")[0].split("@")[1].split("=")[1])//name value
//trace(this.childNodes[a].toString().split("<0>")[1].split("</0>")[0].split("@")[2].split("=")[0])//job variable
//trace(this.childNodes[a].toString().split("<0>")[1].split("</0>")[0].split("@")[2].split("=")[1])//job value
//trace(this.childNodes[a].toString().split("<0>")[1].split("</0>")[0].split("@")[3].split("=")[0])//slary variable
//trace(this.childNodes[a].toString().split("<0>")[1].split("</0>")[0].split("@")[3].split("=")[1])//slary value
}
}
setPixel(1,1,0x0022CC)
}
function mySquare (x:Number, y:Number, size:Number):MovieClip {
var depth:Number = _root.getNextHighestDepth();
var square:MovieClip =_root.createEmptyMovieClip("example",depth);
square.beginFill(0x0022CC, 80);
square.lineStyle(2, 0xFF9900, 100);
square.moveTo(0, 0);
square.lineTo(size, 0);
square.lineTo(size, size);
square.lineTo(0, size);
square.lineTo(0, 0);
square.endFill( );
square._x = x;
square._y = y;
return square;
}
var mc_obj={};
var text_array=[];
var count=0;
var size = 30;
function build_cells(){
for (var j=1; j<10; j++) {
for (var i=1; i<10; i++) {
var x_coord = i * (size + 5);
var y_coord = j * (size + 5);
var tempSquare:MovieClip =mySquare(x_coord+100, y_coord+10, size);
tempSquare.createTextField("data_field", i*j+i+j,size/2-data_field.textWidth/1.6, size/2-data_field.textHeight/1.6, data_field.textWidth*2, data_field.textHeight*2,100);
data_field = tempSquare["data_field"]
data_field.selectable=false
data_field.getNextHighestDepth()
mc_obj["square_"+i+"_"+j]=tempSquare
data_field.text = i+"_"+j;
if(i==1&&j==1){
tempSquare.createTextField("data_field", this.getNextHighestDepth(),size/2-data_field.textWidth/1.6, size/2-data_field.textHeight/1.6, data_field.textWidth*2, data_field.textHeight*2,100);
mc_obj["square_"+1+"_"+1]["data_field"].text=1+"_"+1
}
text_array[count]=mc_obj["square_"+i+"_"+j]["data_field"]
count++
}
}
xmlFile.load("as2.xml");
}
build_cells();
function setPixel(x,y,color){
if(mc_obj["square_"+x+"_"+y]["data_field"].text=="1_1"){
color=0x990000;
}
mc_obj["square_"+x+"_"+y].clear();
mc_obj["square_"+x+"_"+y].beginFill(color, 80);
mc_obj["square_"+x+"_"+y].lineStyle(2, 0xFF9900, 100);
mc_obj["square_"+x+"_"+y].moveTo(0, 0);
mc_obj["square_"+x+"_"+y].lineTo(size, 0);
mc_obj["square_"+x+"_"+y].lineTo(size, size);
mc_obj["square_"+x+"_"+y].lineTo(0, size);
mc_obj["square_"+x+"_"+y].lineTo(0, 0);
mc_obj["square_"+x+"_"+y].endFill( );
}
Last edited by AS3.0; 09-20-2020 at 12:21 AM.
-
-
Client Software Programmer
Last edited by AS3.0; 09-20-2020 at 10:27 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|