Skip to main content
Inspiring
April 19, 2007
Question

Setting the duration of an action

  • April 19, 2007
  • 5 replies
  • 642 views
Is there a way to control the timing and/or blending of the color changes in this code?

import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(pages_main_mc);
trans.colorTransform = colorTrans;

page1_btn.onRelease = function() {
colorTrans.rgb = 0x000000;
trans.colorTransform = colorTrans;
};
page2_btn.onRelease = function() {
colorTrans.rgb = 0xFFFFFF;
trans.colorTransform = colorTrans;
};

Say like a 5 sec period from the time I click the pages2_btn before the color changes to white? In other words the color is black, 3 seconds after clicking the pages2_btn the color is 50% grey and at 5 sec the color is white? Some sort of a timer code for the color change?
This topic has been closed for replies.

5 replies

Inspiring
April 19, 2007
SUPER!!! You rock Kglad! I'm going to look through your code and see what makes things tick. I found the timing for the buttons. One other question and I may find it while looking at the code closer: Anyway for the buttons to have a memory of what the last buttons color was? Say I make page1 button 0000ff and page two ff0000 color is black to start I click page2 and the color goes from black to ff0000 I then hit page 1 and insted of the color going back to black the page one button knows that the current color is ff0000 and fades from that to 0000ff.
Once again thank you
kglad
Community Expert
Community Expert
April 19, 2007
you can use:

Inspiring
April 19, 2007
Ok, so I need to attatch that code and I am guessing add the "col" somewhere in the button code? Sorry, still grasping Flash and I have tried a few ways with no success. I seems I need for the button to know that col (or the current color of pages_main_mc) before it can make a fade to the new color. Humm, or would that mean the "col" needs to be in the fade function. I.E. function starts finds out what the current color is and then proceeds to fade to new color. That would make more sence. Well to me it would LOL but I wouldn't be here asking if I knew would I!
Inspiring
April 19, 2007
Oops
I forgot to delete the ---------------------------------
kglad
Community Expert
Community Expert
April 19, 2007
remove or comment the dotted line.
kglad
Community Expert
Community Expert
April 19, 2007
copy and paste the code you used.
Inspiring
April 19, 2007
import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(pages_main_mc);
trans.colorTransform = colorTrans;

page1_btn.onRelease = function() {
pages_main_mc.colorFadeF(colorTrans.rgb,100,0x000000,100,5,50);
};
page2_btn.onRelease = function() {
pages_main_mc.colorFadeF(colorTrans.rgb,100,0xffffff,100,5,50);
};


-------------------------------------------------------
MovieClip.prototype.colorFadeF = function(rgb1, a1, rgb2, a2, speed, steps) {
if (!var314159) {
var314159 = 1;
trA = ["ra", "rb", "ga", "gb", "ba", "bb", "aa", "ab"];
}
function fadeF(mc) {
if (!mc.repeatPass) {
mc.repeatPass = 1;
}
co = mc.mcCO;
tf2 = mc.tf2;
tf1 = mc.tf1;
steps = mc.steps;
intermediateTF = mc.intermediateTF;
for (var ivar = 0; ivar<trA.length; ivar++) {
num = Math.floor(mc.repeatPass*(tf2[trA[ivar]]-tf1[trA[ivar]])/steps)+tf1[trA[ivar]];
intermediateTF[trA[ivar]] = num.toString();
}
co.setTransform(intermediateTF);
mc.repeatPass++;
if (mc.repeatPass>steps) {
clearInterval(mc.int);
}
updateAfterEvent();
}
this.mcCO = new Color(this);
this.mcCO.setRGB(rgb2);
this._alpha = a2;
this.tf2 = this.mcCO.getTransform();
this.mcCO.setRGB(rgb1);
this._alpha = a1;
this.tf1 = this.mcCO.getTransform();
this.steps = steps;
this.speed = speed;
this.intermediateTF = new Array();
clearInterval(this.int);
this.repeatPass=0;
this.int = setInterval(fadeF, 1000*this.speed/this.steps, this);
};
kglad
Community Expert
Community Expert
April 19, 2007
the code below the dotted line adds a new method to movieclips, colorFadeF().

to use:

Inspiring
April 19, 2007
I'm getting this

**Error** Scene=Scene 1, layer=Action, frame=1:Line 10: Left side of assignment operator must be variable or property.
MovieClip.prototype.colorFadeF = function(rgb1, a1, rgb2, a2, speed, steps) {

Total ActionScript Errors: 1 Reported Errors: 1

I what var or prop am I missing?