Dynamic background color

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, …

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. Code follows in the full message.

//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;


Don't like it? There are lots of published articles, pick a random one.

oCricket

Brajeshwar posted this article on Tue, Feb 18th, 2003 at 5:20 pm
Categorized under Technology and has the following tags

Prev Article: Blogging in news again

Next Article: (mt) got a new look

Archives: Visit the Archives for more articles.

Comments Post Yours

There are 15 responses so far. You can follow any responses to this entry through the RSS feed. You can skip to the end and leave a response. Pinging is currently not allowed.

  1. Thanks brajeshwar This should come in handy.
    I noticed a couple of problems, This fixes it(replace existing code with ):

    var sw = Stage.width + 4;

    and….

      beginFill(col);
    moveTo(rp, rp);
    lineTo(sw, rp);
    lineTo(sw, sh);
    lineTo(rp, sh);
    endFill();

  2. Updated! I did not even test the code beforehand, hhhmmmm. I will take care next time.

  3. If you change the code to the following,
    it also works when you have the Stage.scaleMode set to “NoScale”, and the Stage.align to “LT”

    // We don't want the Flash to Scale
    // but use dynamic alignment instead
    Stage.scaleMode = "noScale"
    Stage.align = "LT"
    
    var rp = 0;//let us have a start point
    
    setBG = function (col) {
     with (_level0) {
      clear();
      if (col != undefined) {
       beginFill(col);
       moveTo(rp, rp);
       //let us add 2 px each as flash eats them
       //in the Stage Object from the actual flash dimension
       lineTo(Stage.width + 4, rp);
       lineTo(Stage.width + 4, Stage.height +4);
       lineTo(rp, Stage.height +4);
       endFill();
    
      }
     }
     this.__bg__ = col;
    };
    //
    getBG = function () {
     return this.__bg__;
    };
    //
    Stage.addProperty("bgColor", getBG, setBG);
    // add a listener to _level0
    // so that the bg is redrawn when a user resizes the Stage
    Stage.addListener(_level0)
    _level0.onResize = function  (){Stage.bgColor = Stage.bgColor}
    delete setBG;
    delete getBG;
    //Usage
    Stage.bgColor = 0x0000ff;
    
  4. // property:
    MovieClip.prototype.addProperty(”bkColor”, function () { return this.bkColor }, function © {
    if (arguments.length <= 0) return;
    var n = this == _root ? {_width : Stage.width + 4, _height: Stage.height + 4} : this;

    with (this) {
    clear();
    beginFill©;
    lineTo(n._width, 0);
    lineTo(n._width, n._height);
    lineTo(0, n._height);
    endFill();
    }

    this.__proto__.bkColor = c;
    });
    // usage:
    this.bkColor = 0xFF0000;
    trace(this.bkColor);

  5. Hey there!
    This script is just what i was looking for but it has one problem it seems.

    For cdrom use i am making a fullscreen projector using these FScommands:
    fscommand(”fullscreen”, “true”);
    fscommand(”showmenu”, “false”);
    fscommand(”allowscale”, “false”);

    Now, when i add this script the background color change works but it does not change the complete background though. it starts it only at the left top of the flash document (at position 0,0). So the top and the right part of the monitor window will be the old background color. How can i fix this and be sure it will work on all resolutions? btw, im a total newbie at actionscripting i have to admit.

    Greets,
    David

  6. David, just replace the initials variables that defines initial position, stage height and stage width to be full screen, in short, use this instead
    moveTo(-2880, -2880);
    lineTo(-2880, 2880);
    lineTo(2880, 2880);
    lineTo(2880, -2880);
    lineTo(-2880, -2880);

  7. AHa great, Thanks!
    What we tried was this;
    var sh = Stage.height + 3000;
    var sw = Stage.width + 3000;
    var rp = -1200;//let us have a start point

    cheers,

    David

  8. one more question now were at it, I am starting with a white background that turns darkblue at scene 2. would it be possible to gradually fade it from white to blue instead of having it switch instantly over 25 frames time for instance?

    :p

  9. can you insert the date to the comments? it would be helpful

  10. i need your help urgently if you feel free and having little bit time to give me to answer my few question that i have bg compenet i have seen your given code and try its work fine after fixing small erors. i want to edit bg color from external text file can you help me to solve this issue actully i have not much experaince in flash i am new but i can say i can work little bit good ………..i hope you will reply me as soon as possible when you have spare time….

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

  12. You are very welcome to visit my website.

    Johny Hobson o

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

  14. 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.

  15. //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 + " &amp; 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;
    

Post yours

Sidenotes

Quick notes, scribbles, somehow related to this website and to what I do. Or perhaps I'm just plain lazy to make them into a full article.

Great Indian Developer Summit 2009

I got a Press Release of the upcoming GIDS '09 and here is an excerpt. The summit's program covers Java, REST, Unit testing, Groovy, Spring, Struts 2.0, SOA, Cloud Computing, Web Services, JRuby, RoR, Ruby, JVM, ...21st Jan, 2009

The flourishing gun market in Pakistan

VICE Travel: Darra, Pakistanby Top-Notch112 (Via: Deep Green Crystals) 20th Jan, 2009

Angry Ringtone for iPhone and others

[audio:http://audio.brajeshwar.com/angry-ring-ring.mp3] The ANGRY RINGTONE for iPhone. (Click the PLAY button above!) Download * iPhone Ringtone (.m4r) * MP3 Ringtone (.mp3) * Zipped (both .m4r and .mp3) To use it as an iPhone Ringtone; just double click the file "angry-ring-ring.m4r" and it ...15th Jan, 2009

IIM Ahmedabad's Leverage 2009

Leverage, the Venture Capital and Private Equity Club of IIM Ahmedabad and the Centre for Innovation Incubation and Entrepreneurship bring to you the 1st edition of the Venture Capital and Private Equity Conference on the ...12th Jan, 2009

Fedora 10 Released

Let's talk history! Fedora was created in late 2003 as a Linux based Operating System which gives the users an admittance from anywhere in the world to the most up-to-date free and open source software ...28th Nov, 2008

View the Sidenotes Archive

Play the Penguin Game

Recommended

  • o! Just Me Of colorful cultures, entertainment, media, life hacks, music, books and movies from hollywood & bollywood.
  • oCricket oCricket is about Cricket and people enthusiastic about it.
  • My Special Job My Special Job is a place where you can look for your weird necessities, strangely superb employees, when your need are more of those hackers, geeks, and ultimate rockstars in the Internet Technology.
  • Ode to Apple Dedicated to Apple - Mac, iPhone, iPod, iTunes, Quicktime, Apple TV and all the awesome softwares for the Apple Mac.
  • Downloads All downloads, Free and Open Source.
  • Not Safe for Work Ever clicked a link and felt embarrassed with the content in front of your co-workers? Ever caught unaware because the funny link your friend sent was a little beyond funny? Let’s minimize that with NSWF.
  • ActionScript 3.0 Reference Flash/Flex ActionScript 3.0 Reference.

Download free Brajeshwar Wordpress Theme

Brajeshwar

Brajeshwar I firmly believe in keeping things simple, easy for users and I envison pushing the technical envelop time and again for the betterment of viable commercial and practical applications. More about me.

Brajeshwar's affinity with Adobe

My Photos

More photos on Flickr

Member of 9rules Network

Since its inception on 11th June, 2001, "Brajeshwar" has 949 Articles and 6,472 comments, contained within 22 categories and 1,497 tags.