A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: How to change the color of a cell of the table

  1. #1
    Senior Member
    Join Date
    May 2016
    Posts
    133

    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:Numbery:Numbersize:Number):MovieClip {
            var 
    depth:Number _root.getNextHighestDepth( );
    var 
    square:MovieClip =_root.createEmptyMovieClip("example"depth);
    square.beginFill(0x0022CC80);
    square.lineStyle(20xFF9900100);
    square.moveTo(00);
    square.lineTo(size0);
    square.lineTo(sizesize);
    square.lineTo(0size);
    square.lineTo(00);
    square.endFill( );
    square._x x;
    square._y y;
    return 
    square;
    }
    var 
    size 30;
    for (
    i=0i<10i++) {
    for (
    j=0j<10j++) {
    var 
    x_coord * (size 5);
    var 
    y_coord * (size 5);
    var 
    tempSquare:MovieClip =mySquare(x_coord+100y_coord+10size);
    }
    }


  2. #2
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    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:Numbery:Numbersize:Number):MovieClip {
    var 
    depth:Number _root.getNextHighestDepth( );
    var 
    square:MovieClip =_root.createEmptyMovieClip("example"depth);
    square.beginFill(0x0022CC80);
    square.lineStyle(20xFF9900100);
    square.moveTo(00);
    square.lineTo(size0);
    square.lineTo(sizesize);
    square.lineTo(0size);
    square.lineTo(00);
    square.endFill( );
    square._x x;
    square._y y;

    return 
    square;
    }
    var 
    size 30;
    for (
    i=0i<10i++) {
    for (
    j=0j<10j++) {
    var 
    x_coord * (size 5);
    var 
    y_coord * (size 5);
    var 
    tempSquare:MovieClip =mySquare(x_coord+100y_coord+10size);
    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(color80);
    mc_obj["square_"+x+"_"+y].lineStyle(20xFF9900100);
    mc_obj["square_"+x+"_"+y].moveTo(00);
    mc_obj["square_"+x+"_"+y].lineTo(size0);
    mc_obj["square_"+x+"_"+y].lineTo(sizesize);
    mc_obj["square_"+x+"_"+y].lineTo(0size);
    mc_obj["square_"+x+"_"+y].lineTo(00);
    mc_obj["square_"+x+"_"+y].endFill( );



    ----------------------------------------------------------------------------------------------------------------------------------------
    example 2:
    PHP Code:

    var mc_obj={};

    function 
    mySquare (x:Numbery:Numbersize:Number):MovieClip {
    var 
    depth:Number _root.getNextHighestDepth( );
    var 
    square:MovieClip =_root.createEmptyMovieClip("example"depth);
    square.beginFill(0x0022CC80);
    square.lineStyle(20xFF9900100);
    square.moveTo(00);
    square.lineTo(size0);
    square.lineTo(sizesize);
    square.lineTo(0size);
    square.lineTo(00);
    square.endFill( );
    square._x x;
    square._y y;

    return 
    square;
    }
    var 
    size 30;
    for (
    i=0i<10i++) {
    for (
    j=0j<10j++) {
    var 
    x_coord * (size 5);
    var 
    y_coord * (size 5);
    var 
    tempSquare:MovieClip =mySquare(x_coord+100y_coord+10size);
    mc_obj["square_"+i+"_"+j]=tempSquare
    }
    }
    var 
    num=0
    onEnterFrame
    =function(){
    for (
    i=0i<10i++) {
    for (
    j=0j<10j++) {
    setPixel(i,j,num);
    num++
    }
    }
    }
    function 
    setPixel(x,y,color){
    mc_obj["square_"+x+"_"+y].clear();
    mc_obj["square_"+x+"_"+y].beginFill(color80);
    mc_obj["square_"+x+"_"+y].lineStyle(20xFF9900100);
    mc_obj["square_"+x+"_"+y].moveTo(00);
    mc_obj["square_"+x+"_"+y].lineTo(size0);
    mc_obj["square_"+x+"_"+y].lineTo(sizesize);
    mc_obj["square_"+x+"_"+y].lineTo(0size);
    mc_obj["square_"+x+"_"+y].lineTo(00);
    mc_obj["square_"+x+"_"+y].endFill( );

    Last edited by Alloy Bacon; 09-18-2020 at 12:37 PM.

  3. #3
    Senior Member
    Join Date
    May 2016
    Posts
    133
    thaaaaaaaaaaaaaaank yoooooooooooooooou

    how can i write into cells

  4. #4
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    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:Numbery:Numbersize:Number):MovieClip {
    var 
    depth:Number _root.getNextHighestDepth();
    var 
    square:MovieClip =_root.createEmptyMovieClip("example",depth);
    square.beginFill(0x0022CC80);
    square.lineStyle(20xFF9900100);
    square.moveTo(00);
    square.lineTo(size0);
    square.lineTo(sizesize);
    square.lineTo(0size);
    square.lineTo(00);
    square.endFill( );
    square._x x;
    square._y y;

    return 
    square;
    }

    var 
    size 30;
    for (var 
    j=1j<10j++) {
    for (var 
    i=1i<10i++) {
    var 
    x_coord * (size 5);    
    var 
    y_coord * (size 5);
    var 
    tempSquare:MovieClip =mySquare(x_coord+100y_coord+10size);

    tempSquare.createTextField("data_field"i*j+i+j,size/2-data_field.textWidth/1.6size/2-data_field.textHeight/1.6data_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.6size/2-data_field.textHeight/1.6data_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(color80);
    mc_obj["square_"+x+"_"+y].lineStyle(20xFF9900100);
    mc_obj["square_"+x+"_"+y].moveTo(00);
    mc_obj["square_"+x+"_"+y].lineTo(size0);
    mc_obj["square_"+x+"_"+y].lineTo(sizesize);
    mc_obj["square_"+x+"_"+y].lineTo(0size);
    mc_obj["square_"+x+"_"+y].lineTo(00);
    mc_obj["square_"+x+"_"+y].endFill( );

    Last edited by Alloy Bacon; 09-19-2020 at 12:19 AM.

  5. #5
    Senior Member
    Join Date
    May 2016
    Posts
    133

    can you load string data from txt file into cells

    thanks and respect

  6. #6
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    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.

  7. #7
    Senior Member
    Join Date
    May 2016
    Posts
    133
    local in the same folder to run from desktop


    Last edited by kofa; 09-19-2020 at 12:17 PM.

  8. #8
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    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:Numbery:Numbersize:Number):MovieClip {
    var 
    depth:Number _root.getNextHighestDepth();
    var 
    square:MovieClip =_root.createEmptyMovieClip("example",depth);
    square.beginFill(0x0022CC80);
    square.lineStyle(20xFF9900100);
    square.moveTo(00);
    square.lineTo(size0);
    square.lineTo(sizesize);
    square.lineTo(0size);
    square.lineTo(00);
    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=1j<10j++) {
    for (var 
    i=1i<10i++) {
    var 
    x_coord * (size 5);    
    var 
    y_coord * (size 5);
    var 
    tempSquare:MovieClip =mySquare(x_coord+100y_coord+10size);

    tempSquare.createTextField("data_field"i*j+i+j,size/2-data_field.textWidth/1.6size/2-data_field.textHeight/1.6data_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.6size/2-data_field.textHeight/1.6data_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(color80);
    mc_obj["square_"+x+"_"+y].lineStyle(20xFF9900100);
    mc_obj["square_"+x+"_"+y].moveTo(00);
    mc_obj["square_"+x+"_"+y].lineTo(size0);
    mc_obj["square_"+x+"_"+y].lineTo(sizesize);
    mc_obj["square_"+x+"_"+y].lineTo(0size);
    mc_obj["square_"+x+"_"+y].lineTo(00);
    mc_obj["square_"+x+"_"+y].endFill( );

    Last edited by Alloy Bacon; 09-20-2020 at 12:21 AM.

  9. #9
    Senior Member
    Join Date
    May 2016
    Posts
    133

  10. #10
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    not a problem.
    Last edited by Alloy Bacon; 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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center