Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-20-2002, 04:24 PM   #1
jpe2001
Registered User
 
Join Date: Jul 2002
Location: Birmingham, England
Posts: 7
Default Smooth scripted colour changes?

Does anyone know how to animate a colour change with script? Rather than creating a tweening animation. Having script gradually change a background graphic from a black to a grey for example.

I know there is an example in the Actionscript Reference which just changes the colour one jump. I want a nice smooth graduation between 2 colours.

Links to any tutorials on this subject would be very helpful to get the ball rolling.


Many Thanks
Jon-Paul
jpe2001 is offline   Reply With Quote
Old 07-21-2002, 02:19 AM   #2
Jesse
ActionScript.org Founder
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: New York
Posts: 8,736
Default

I did this for a commercial product. Without showing you the source I can say it involved splitting a HEX color code into its R, G and B components, then dividing the difference between the initial R and target R by how many steps you want to make (the more, the smoother the tween), then changing the color to the current R plus the step factor. Then doing the same for G and B. It sounds harder than it is. (Note I did this in Flash 5.. in Flash MX there may be a better way which I aint seen yet). In fact... look into setTransform because I think that can handle such things. My application was slightly different and could not use that method.
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Old 07-21-2002, 01:44 PM   #3
jpe2001
Registered User
 
Join Date: Jul 2002
Location: Birmingham, England
Posts: 7
Default colour changing script

Any suggestions?

I have been given some script (see below) which looks right but isn't working.

Can i briefly explain what i've done with scrpt which contains the r g b Hex components you mentioned:

In the first frame of my timeline I've put the first piece of script with a movieclip i've created with the instance name 'prototype', inside the movieclip i've placed the second piece of script with a coloured shape and a button with the third piece of script which triggers the colour change cycle.

1. TIMELINE SCRIPT

movieclip.prototype.fademe=function(){
with(myvals){
ra+=(_parent.targvals.ra-ra)/speed
ga+=(_parent.targvals.ga-ga)/speed
ba+=(_parent.targvals.ba-ba)/speed
rb+=(_parent.targvals.rb-rb)/speed
gb+=(_parent.targvals.gb-gb)/speed
bb+=(_parent.targvals.bb-bb)/speed
}
col.setTransform(myvals);


2. MOVIE CLIP SCRIPT

onClipEvent (load) {
col = new Color(this);
_parent.targvals = myvals=col.getTransform();
speed = 15;
}
onClipEvent (enterFrame) {
fademe();
}

3. BUTTON SCRIPT

on (release) {
_root.targvals = {ra:100, ga:100, ba:76, rb:55, gb:41, bb:23};
}



I'm not absolutely sure whether i'm placing the script in right places.

Thanks
Jon-Paul
jpe2001 is offline   Reply With Quote
Old 07-21-2002, 07:30 PM   #4
jpe2001
Registered User
 
Join Date: Jul 2002
Location: Birmingham, England
Posts: 7
Default right direction

Good example, in Chapter 5 of Actionscript Studio. (color_setTransform.fla)
*
http://www.friendsofed.com/books/stu...ript/code.html

which answers the original question.
jpe2001 is offline   Reply With Quote
Old 07-22-2002, 02:47 AM   #5
Jesse
ActionScript.org Founder
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: New York
Posts: 8,736
Default

Yeah that's a cool example.
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Old 07-22-2002, 12:10 PM   #6
jpe2001
Registered User
 
Join Date: Jul 2002
Location: Birmingham, England
Posts: 7
Default Another great example

Check this one out as well, same thing, different concept.

http://www.FlashFugitive.com/color_text1.swf

http://www.FlashFugitive.com/color_text1.fla

courtsey of urami
http://webforums.macromedia.com/flas...401508#1430280

Jon-Paul
jpe2001 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
smooth colour change smudgexxx ActionScript 1.0 (and below) 3 10-09-2003 11:06 PM
saving a colour SO sonic_2k_uk ActionScript 1.0 (and below) 7 06-10-2003 06:28 PM
MX colour problem? Mortimer Jazz ActionScript 1.0 (and below) 5 04-14-2003 01:03 PM
swf colour and html colour idonthaveaname Simple Stuff (Newbies) 3 02-06-2003 01:39 PM
Changing colour of objects dynamically jimpark ActionScript 1.0 (and below) 1 07-26-2002 04:19 PM


All times are GMT. The time now is 01:34 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.