Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Actionscripting

Categories How to Create a Flash MX Component
Author: Jonathan Kaye | Website: http://www.amethyst-research.com |

 
Page 19
«prev ... 12 13 14 15 16 17 18 19 20 21 22 23 24 25 next»

Ready or Not, Here we Code

10. The final step is to write the code for the custom UI. In a new layer, enter the following into frame 1:

fscommand("allowscale", "false");
// Set the default property values
xch.tbase = 10;
xch.theight = 10;
xch.tcolor = 0x000000;
xch.applyTint = false;
// Initialize the base and height text fields
bs.text = 10;
ht.text = 10;
compute_fuqu(10, 10);
// Initialize the tint tile and color text fields
tsc = new Color(tintSq);
rc.text = gc.text = bc.text = "0";
setTintSq(0, 0, 0);

// Given a base and height value, compute the fuqu and set the
// fuqu indicator based on the computed value
function compute_fuqu (b, h) {
var fuqu;

if (isNaN(b))
b = 0;
if (isNaN(h))
h = 0;

fuqu = b/h * 4.211;

if (fuqu == 4.211) {
fuquEval.gotoAndStop(1);
} else if (fuqu>= 2.211 && fuqu <= 6.211) {
fuquEval.gotoAndStop(2);
} else {
fuquEval.gotoAndStop(3);
}
// Set the text field that shows the fuqu
fuquTF.text = Math.round(fuqu * 1000) / 1000;
}

// Given a red, green, and blue color value (0-255), create a composite
// color value, set the tint tile, and return the composite color value.
function setTintSq(r, g, b) {
var col = r <<16 | g <<8 | b;
tsc.setRGB(col);
return col;
}

// When the base and height text fields change, recompute the fuqu
// and set the appropriate property in xch
bs.onChanged = function () {
xch.tbase = this.text;
compute_fuqu(ParseFloat(this.text), ParseFloat(xch.theight));
}
ht.onChanged = function () {
xch.theight = this.text;
compute_fuqu(ParseFloat(xch.tbase), ParseFloat(this.text));
}

// Given an integer c, clamp it to values between 0 and 255
function boundColor (c) {
if (isNaN(c))
return 0;
if (c <0) {
c = 0;
} else if (c> 255) {
c = 255;
}
return c;
}

// When the color text fields change, change the tint color
// and set the appropriate property in xch
rc.onChanged = function () {
xch.tcolor = setTintSq(boundColor(this.text), ParseInt(gc.text), ParseInt(bc.text));
}
gc.onChanged = function () {
xch.tcolor = setTintSq(ParseInt(rc.text), boundColor(this.text), ParseInt(bc.text));
}
bc.onChanged = function () {
xch.tcolor = setTintSq(ParseInt(rc.text), ParseInt(bc.text), boundColor(this.text));
}

// The check box (c) calls this function when the user checks or unchecks
// the box. Set the applyTint property of xch appropriately.
function tintApply (c) {
xch.applyTint = c.getValue();
}

«prev ... 12 13 14 15 16 17 18 19 20 21 22 23 24 25 next»

» Level Intermediate

Added: : 2002-04-16
Rating: 8.42 Votes: 54
Hits: 903
» Author
Jonathan Kaye, PhD, is the President and CTO of Amethyst Research LLC, an award-winning interactive design and engineering firm specializing in the creation of online device simulations. He and David Castillo are the authors of "Flash for Interactive Simulation: How to Construct and Use Device Simulations", to be published by Delmar Thomson Learning in November, 2002 (the accompanying web site will be www.FlashSim.com).
» Download
Download the files used in this tutorial.
Download (0 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers