A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Changing colours using Actionscript.

  1. #1
    Ivor1 ivor1's Avatar
    Join Date
    Aug 2006
    Location
    Dundee, Scotland
    Posts
    478

    Changing colours using Actionscript.

    I am starting to learn AS2.0. Can someone show me how to change a colour in a movie clip via Actionscript? For instance, say the clip starts off red and I want it to change to blue then green and finally red again? How would I do that?
    I really want to learn this so any help is much appreciated.

  2. #2
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    here is a link that should help you. Download the BitmapData class tut (1st one)

  3. #3
    Ivor1 ivor1's Avatar
    Join Date
    Aug 2006
    Location
    Dundee, Scotland
    Posts
    478
    Thanks. This colour picker tutorial certainly looks informative but it's going to take a while to learn. Ideally, I would like to have a movie clip whose background colour fades continuously through the spectrum and this has set me on the right course. Any more advice on achieving this is most welcome though.

  4. #4
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    will have you a sample later

  5. #5
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    silentweed posted this in another forum - it should do what you want.

    have a look at colorshifter application at http://www.braingiants.com/ for an example of background color fades

  6. #6
    Ivor1 ivor1's Avatar
    Join Date
    Aug 2006
    Location
    Dundee, Scotland
    Posts
    478
    Thanks, wattsup. That's a very cool site. I'm getting closer now to what I want. I just have to figure how to get the colours to change by themselves, without interaction.
    That is, a white stage with a small movie clip on it with the m_c's colours fading through the spectrum, perhaps randomly.

  7. #7

  8. #8
    Ivor1 ivor1's Avatar
    Join Date
    Aug 2006
    Location
    Dundee, Scotland
    Posts
    478
    I'll try set interval but it's gonna take a while. This is more involved than I first
    thought. Thanks for helping.

  9. #9
    Member
    Join Date
    May 2007
    Posts
    38

    Use the built in SetRGB(); Function

    Haven't checked out others help, but you should definitely use the setRGB function. Paste this is in first frame of your flash movie.

    // *************************** //
    // MovieClip.setRGB() method //
    //this is a built in function which allows us to set the color of the lots from the text file.

    MovieClip.prototype.setRGB = function(newColor) {
    (new Color(this)).setRGB(newColor);
    } // end MovieClip.setRGB()

    // *************************** //

    Then you would type something like this:

    _root.map.lot1bg.setRGB(_root.lotInfo.lot1color);

    where _root.map.lot1bg is the path of the movie clip who's bg you are changing, and lot1color is just a variable I set in an external document and imported.

    I think you can then use the new built in mx transition tweens to swap between colors, and you can use the parameter that allows you to run a function when the tween is done (I forget what it is called - just look up mx.transitions and it will explain) - that way you could set up a repeating function. I wouldn't advise using setInterval here - that will get messy, and slow things down for no reason...let me know if you need more help and I could give you better details -

  10. #10
    Ivor1 ivor1's Avatar
    Join Date
    Aug 2006
    Location
    Dundee, Scotland
    Posts
    478
    I am going to try this "setRGB" function but as I'm a shade green to AS, it's going to take me a while. I can't start till later on but do I have to create and import another file as per your lot1colour? Many thanks for your help.

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