Autochrome Photography Wordpress theme for just $25. Get Yours

Dynamic background color

— By

Peter Hall posted a solution to setting the background color using Actionscript, actually drawing a rectangle on the background below any other elements on the document. Someone on the Macromedia Flash Forum re-iterated that question, so I thought some of you may still would like to have a look at a modified version.

This one will only fill the viewable stage and not the whole maximum allowable space of 5760 px of the Flash Document Scene.


//define a var for sh and sw
//let us add 2 px each as flash eats them
//in the Stage Object from the actual flash dimension
var sh = Stage.height + 4;
var sw = Stage.width + 4;
var rp = 0; //let us have a start point
trace("stage height = " + sh + "& stage width = " + sw + " in pixels");
setBG = function (col) {
 with (_level0) {
  clear();
  if (col != undefined) {
   beginFill(col);
   moveTo(rp, rp);
   lineTo(sw, rp);
   lineTo(sw, sh);
   lineTo(rp, sh);
   endFill();
  }
 }
 this.__bg__ = col;
};
//
getBG = function () {
 return this.__bg__;
};
//
Stage.addProperty("bgColor", getBG, setBG);
delete setBG;
delete getBG;

//Usage
Stage.bgColor = 0x0000ff;

Brajeshwar

Brajeshwar believes in simplicity; pushes the envelop and envisions the betterment of usable and practical solutions.

More by Brajeshwar

  • http://www.artstarstudio.com Carey Richardosn

    I keep getting a static script error on this code? i'm using Mx pro 2004? Please help...

  • http://www.artstarstudio.com Carey Richardosn

    I keep getting a static script error on this code? i'm using Mx pro 2004? Please help...

  • Johny Hobson

    You are very welcome to visit my website.

    Johny Hobson o

  • Johny Hobson

    You are very welcome to visit my website.

    Johny Hobson o

  • Lewis

    I like this BUT just wondering what the 'this.__bg__ = col;' and 'return this.__bg__' are for??

  • Lewis

    I like this BUT just wondering what the 'this.__bg__ = col;' and 'return this.__bg__' are for??

  • Per Jensen

    Could this dynamic background color, script by any chance be put into flash 8 scripting. I have tryed but cant seem to figure it out. Thank you.

  • Per Jensen

    Could this dynamic background color, script by any chance be put into flash 8 scripting. I have tryed but cant seem to figure it out. Thank you.

  • le boudouil

    //define a var for sh and sw
    //let us add 2 px each as flash eats them
    //in the Stage Object from the actual flash dimension
    var sh = Stage.height + 4;
    var sw = Stage.width + 4;
    var rp = 0;//let us have a start point
    trace("stage height = " + sh + " & stage width = " + sw + " in pixels");
    setBG = function (col) {
    with (_level0) {
    clear();
    if (col != undefined) {
    beginFill(col);
    moveTo(rp, rp);
    lineTo(sw, rp);
    lineTo(sw, sh);
    lineTo(rp, sh);
    endFill();
    }
    }
    this.__bg__ = col;
    };
    //
    getBG = function () {
    return this.__bg__;
    };
    //
    Stage.addProperty("bgColor", getBG, setBG);
    delete setBG;
    delete getBG;
    //Usage
    Stage.bgColor = 0x0000ff;

  • le boudouil
    //define a var for sh and sw
    //let us add 2 px each as flash eats them
    //in the Stage Object from the actual flash dimension
    var sh = Stage.height + 4;
    var sw = Stage.width + 4;
    var rp = 0;//let us have a start point
    trace("stage height = " + sh + " & stage width = " + sw + " in pixels");
    setBG = function (col) {
     with (_level0) {
      clear();
      if (col != undefined) {
       beginFill(col);
       moveTo(rp, rp);
       lineTo(sw, rp);
       lineTo(sw, sh);
       lineTo(rp, sh);
       endFill();
      }
     }
     this.__bg__ = col;
    };
    //
    getBG = function () {
     return this.__bg__;
    };
    //
    Stage.addProperty("bgColor", getBG, setBG);
    delete setBG;
    delete getBG;
    //Usage
    Stage.bgColor = 0x0000ff;
    
Teknopoint Multimedia - Adobe Training, Design and Development, RIA Consulting. Teknopoint Multimedia - Adobe Training, Design and Development, RIA Consulting.

Themes