Adobe Dreamweaver Forums



Last 10 THreads :         Issue with Firefox & Flash Player Installation (Last Post : hhgttg - Replies : 1 - Views : 29 )           »          Up Button Event Handling Problem (Last Post : ABCJARED - Replies : 0 - Views : 1 )           »          audio (Last Post : Captiv8r - Replies : 1 - Views : 2 )           »          Kintana Dummy Page (Last Post : KiahMom - Replies : 4 - Views : 5 )           »          Dreamweaver CS3 Problem on Windows Vista (Last Post : confused_pam - Replies : 14 - Views : 15 )           »          adobe flash player installs but doesn't play (Last Post : kellyg1 - Replies : 1 - Views : 2 )           »          Video Conversion adds slight gray background (Last Post : JRStaf4ord - Replies : 0 - Views : 1 )           »          help getting links in scrolling menu to work (Last Post : NedWebs - Replies : 11 - Views : 12 )           »          left join won't work in query of query? (Last Post : Ian Skinner - Replies : 4 - Views : 5 )           »          Video Conversion adds slight gray background (Last Post : JRStaf4ord - Replies : 1 - Views : 2 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 12-04-2008, 07:42 PM
SiHoop
 
Posts: n/a
Diggs:
Default Fill graphics

I'm trying to make a timer in the form of a circle that fills as time passes. I
found some code to create the circle, but now I want to fill the circle as the
'hand' of the clock sweeps. My problem is that I cannot figure out how to fill
successive circle segments with color. Instead, I appear to be filling a
rectangle, but that does not achieve my goal of a smooth fill. I think the code
below will clarify my issue. Does anyone know how I can fill successive
segments as the clock arm continues to sweep?

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init()">
<mx:UIComponent id="mainDisplay"/>
<mx:Script>
<![CDATA[
import flash.display.Shape;
import flash.events.TimerEvent;
import flash.utils.Timer;

private var shape1:Shape
private function init():void {
var myTimer:Timer = new Timer(200);
var timeInterval:int=0
myTimer.addEventListener("timer", timerHandler);
myTimer.start();
function timerHandler():void{
timeInterval+=10
drawWedge(100,300, timeInterval, 360, 200, 200)
}
}
private function drawWedge(x, y, startAngle, arc, radius, yRadius):void {
var segAngle:Number
var theta:Number
var angle:Number
var angleMid:Number
var segs:Number
var ax:Number
var ay:Number
var bx:Number
var by:Number
var cx:Number
var cy:Number
// Flash uses 8 segments per circle, to match that, we draw in a maximum
// of 45 degree segments. First we calculate how many segments are needed
// for our arc.
segs = Math.ceil(Math.abs(arc)/45);
// Now calculate the sweep of each segment.
segAngle = arc/segs;
// The math requires radians rather than degrees. To convert from degrees
// use the formula (degrees/180)*Math.PI to get radians.
theta = -(segAngle/180)*Math.PI;
// convert angle startAngle to radians
angle = -(startAngle/180)*Math.PI;
// draw the curve in segments no larger than 45 degrees.
if (segs>0) {
// draw a line from the center to the start of the curve
ax = x+Math.cos(startAngle/180*Math.PI)*radius;
ay = y+Math.sin(-startAngle/180*Math.PI)*yRadius;
shape1=new Shape
shape1.graphics.moveTo(x, y);
shape1.graphics.lineStyle(1, 0xFFff00);
shape1.graphics.lineTo(ax, ay);
// Loop for drawing curve segments
for (var i:int = 0; i<segs; i++) {
angle += theta;
angleMid = angle-(theta/2);
bx = x+Math.cos(angle)*radius;
by = y+Math.sin(angle)*yRadius;
cx = x+Math.cos(angleMid)*(radius/Math.cos(theta/2));
cy = y+Math.sin(angleMid)*(yRadius/Math.cos(theta/2));
shape1.graphics.curveTo(cx, cy, bx, by);
}
mainDisplay.addChild(shape1)
// close the wedge by drawing a line to the center
shape1.graphics.beginFill(0xFF0000);
shape1.graphics.lineTo(x, y);
shape1.graphics.endFill();
}
};
]]>
</mx:Script>
</mx:Application>



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-04-2008, 08:42 PM
rtalton
 
Posts: n/a
Diggs:
Default Re: Fill graphics

Wow, this your lucky day!
Flex pretty much sucks at drawing graphics, but the DeGrafa people have a cool
framework you can use. I understand that Adobe has been working with DeGrafa to
add such graphics capabilities to Flex 4.

here is an example of a timer:
http://dean-logan.com/demo/Flex/EggTimer/

here is the DeGrafa website:
http://degrafa.org/samples/

Give it a try and see what you think.

Reply With Quote
  #3 (permalink)  
Old 12-05-2008, 08:23 PM
SiHoop
 
Posts: n/a
Diggs:
Default Re: Fill graphics

This was great-- thanks!
Reply With Quote


Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 09:26 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Cheap Car Insurance - Compare Motor Insurance
Endsleigh Car Insurance Natwest Car Insurance
More Than Car Insurance Norwich Union Car Insurance
Prudential Car Insurance Zurich Car Insurance
Inactive Reminders By Mished.co.uk