A Flash Developer Resource Site

Results 1 to 7 of 7

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

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

    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,083
    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; Yesterday at 12:37 PM.

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

    how can i write into cells

  4. #4
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,083
    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; Today at 12:19 AM.

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

    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,083
    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
    132
    local in the same folder to run from desktop


    Last edited by kofa; Today at 12:17 PM.

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