Re: [Flashcoders] My first code.

2010-12-15 Thread spyder spyders
Thank You So Much! :DI have been researching for over a 
month!!  I am guessing that the 'this'  is pointing to the symbol or _mc I 
attach the class to? 
I ended up doing away with all of the  "this" because I was receiving an error 
message saying  "gotoAndStop is not a function."  Also I needed to declare the 
variable  "buttonState"

Here it is!!! My first Class! 
Thank you!



###

package
{

import flash.display.MovieClip;
import flash.events.MouseEvent;


public class ToggleButton extends MovieClip
{
//public var togglButton:MovieClip;
public var buttonState = MovieClip;

public function ToggleButton()
{
// constructor code



//event listeners
addEventListener(MouseEvent.MOUSE_OVER, rolloverToggle);
addEventListener(MouseEvent.MOUSE_OUT, rolloutToggle);
addEventListener(MouseEvent.CLICK, toggleClick);
buttonState = "off";


// Respond to mouse events
function rolloverToggle(event:MouseEvent)
{
gotoAndStop(buttonState+" over");

} //rollover f(x)

function rolloutToggle(event:MouseEvent)
{
gotoAndStop(buttonState);

} //rollout f(x)

function toggleClick(event:MouseEvent)
{
if (buttonState == "on")
{
buttonState = "off";
} //if
else
{
buttonState = "on";
} //else
gotoAndStop(buttonState+" over");

} //toggle click f(x)

} //constructor f(x)

} //class

} //package



#
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] My first code.

2010-12-15 Thread Paul Andrews

On 15/12/2010 23:53, spyder spyders wrote:

   HELLO FlashCoders!

   I am trying to write a ToggleButton Class.I can get it to work as a 
document class and as as3 on timeline.  But how to I use it as a symbol class?


Everywhere you have "toggleButton" replace it with "this" or remove it 
altogether.

In the linkage for the MovieClip that represents the toggle, put this class.

Paul



Thx!
/

package
{

import flash.display.MovieClip;
import flash.events.MouseEvent;


public class ToggleButton extends MovieClip
{
public var toggleButton:MovieClip;

public function ToggleButton()
{
// constructor code



//event listeners
toggleButton.addEventListener(MouseEvent.MOUSE_OVER, 
rolloverToggle);
toggleButton.addEventListener(MouseEvent.MOUSE_OUT, 
rolloutToggle);
toggleButton.addEventListener(MouseEvent.CLICK, 
toggleClick);
toggleButton.buttonState = "off";


// Respond to mouse events
function rolloverToggle(event:MouseEvent)
{
toggleButton.gotoAndStop(toggleButton.buttonState+" 
over");

} //rollover f(x)

function rolloutToggle(event:MouseEvent)
{

toggleButton.gotoAndStop(toggleButton.buttonState);

} //rollout f(x)

function toggleClick(event:MouseEvent)
{
if (toggleButton.buttonState == "on")
{
toggleButton.buttonState = "off";
} //if
else
{
toggleButton.buttonState = "on";
} //else
toggleButton.gotoAndStop(toggleButton.buttonState+" 
over");

} //toggle click f(x)

} //constructor f(x)

} //class

} //package


/
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] My first code.

2010-12-15 Thread spyder spyders
  HELLO FlashCoders!

  I am trying to write a ToggleButton Class.I can get it to work as a 
document class and as as3 on timeline.  But how to I use it as a symbol class? 
Thx!
/

package 
{

import flash.display.MovieClip;
import flash.events.MouseEvent;


public class ToggleButton extends MovieClip
{
public var toggleButton:MovieClip;

public function ToggleButton()
{
// constructor code



//event listeners
toggleButton.addEventListener(MouseEvent.MOUSE_OVER, 
rolloverToggle);
toggleButton.addEventListener(MouseEvent.MOUSE_OUT, 
rolloutToggle);
toggleButton.addEventListener(MouseEvent.CLICK, 
toggleClick);
toggleButton.buttonState = "off";


// Respond to mouse events
function rolloverToggle(event:MouseEvent)
{

toggleButton.gotoAndStop(toggleButton.buttonState+" over");

} //rollover f(x)

function rolloutToggle(event:MouseEvent)
{

toggleButton.gotoAndStop(toggleButton.buttonState);

} //rollout f(x)

function toggleClick(event:MouseEvent)
{
if (toggleButton.buttonState == "on")
{
toggleButton.buttonState = "off";
} //if
else
{
toggleButton.buttonState = "on";
} //else

toggleButton.gotoAndStop(toggleButton.buttonState+" over");

} //toggle click f(x)

} //constructor f(x)

} //class

} //package


/
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] problem with adding two digits

2010-12-15 Thread Anthony Pace

Oh yeah, I forgot to give some examples to test it with, so...

trace(floatSum(-0.1,0.9155,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1));
//vs
trace(-0.1+0.9155+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1);
//and
trace(floatProduct(2.1,0.1,1.0001,.0001));
//vs
trace(2.1*0.1*1.0001*.0001);


On 12/15/2010 2:25 PM, Anthony Pace wrote:
I wrote the functions below in literally just a few min, so, even 
though they do seem to work for me, I wouldn't necessarily say they 
are production ready.


Also, I would only use these if you will know that the numbers past 
the mantissa are of small amounts.


Oh yeah, and please tell me if I screwed up somewhere, or if you think 
you can do it better :)


function floatProduct(... nums){
var ml:int = 0; //max length past mantissa
var ln:uint = nums.length;
var rsl:int; //right side length
var p:Number = 1;
var s:String;
for (var i:uint = 0; i< ln; ++i) {
s = nums[i].toString();
rsl = s.length - s.indexOf('.');
ml += rsl;
p *= nums[i];
}
return Number(p.toFixed(ml));
}
function floatSum(... nums){
var ml:int = 0; //max length past mantissa
var ln:uint = nums.length;
var rsl:int; //right side length
var p:Number = 0;
var s:String;
for (var i:int = 0; i< ln; ++i) {
s = nums[i].toString();
rsl = s.length - s.indexOf('.');
if (rsl > ml) {
ml = rsl;
}
p += nums[i];
}
return Number(p.toFixed(ml));
}


-




On 12/14/2010 12:05 PM, Kerry Thompson wrote:

Adrian Zając wrote:



trace (0.27 + 0.03);   // output -->  0.30004

Can anyone tell me why I get this weird result in output window?


As people have said, it's a problem with decimals. It's not a problem 
with

Flash--it's a problem with binary numbers.

Integers are accurate because all integers are a multiple of 1, and 
binary
does just fine with combining 0's and 1's, the only possibile values 
of a

digit in the binary system.

If you think of decimals as fractions, maybe it will help you 
understand the
issue. In binary, a digit can only be a multiple of 2: 1/2, 1/4, 1/8/ 
1/16,

1/32, and so on. You can create numbers that aren't multiples of two by
adding multiple digits. For example, 1/4 + 1/8 = 3/8, or .375.

This works pretty well, until you get numbers with a lot of decimal 
places.

At some point, you will find a decimal that is impossible to make using
powers of 2.

Cordially,

Kerry Thompson
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] problem with adding two digits

2010-12-15 Thread Anthony Pace
I wrote the functions below in literally just a few min, so, even though 
they do seem to work for me, I wouldn't necessarily say they are 
production ready.


Also, I would only use these if you will know that the numbers past the 
mantissa are of small amounts.


Oh yeah, and please tell me if I screwed up somewhere, or if you think 
you can do it better :)


function floatProduct(... nums){
var ml:int = 0; //max length past mantissa
var ln:uint = nums.length;
var rsl:int; //right side length
var p:Number = 1;
var s:String;
for (var i:uint = 0; i< ln; ++i) {
s = nums[i].toString();
rsl = s.length - s.indexOf('.');
ml += rsl;
p *= nums[i];
}
return Number(p.toFixed(ml));
}
function floatSum(... nums){
var ml:int = 0; //max length past mantissa
var ln:uint = nums.length;
var rsl:int; //right side length
var p:Number = 0;
var s:String;
for (var i:int = 0; i< ln; ++i) {
s = nums[i].toString();
rsl = s.length - s.indexOf('.');
if (rsl > ml) {
ml = rsl;
}
p += nums[i];
}
return Number(p.toFixed(ml));
}


-




On 12/14/2010 12:05 PM, Kerry Thompson wrote:

Adrian Zając wrote:



trace (0.27 + 0.03);   // output -->  0.30004

Can anyone tell me why I get this weird result in output window?


As people have said, it's a problem with decimals. It's not a problem with
Flash--it's a problem with binary numbers.

Integers are accurate because all integers are a multiple of 1, and binary
does just fine with combining 0's and 1's, the only possibile values of a
digit in the binary system.

If you think of decimals as fractions, maybe it will help you understand the
issue. In binary, a digit can only be a multiple of 2: 1/2, 1/4, 1/8/ 1/16,
1/32, and so on. You can create numbers that aren't multiples of two by
adding multiple digits. For example, 1/4 + 1/8 = 3/8, or .375.

This works pretty well, until you get numbers with a lot of decimal places.
At some point, you will find a decimal that is impossible to make using
powers of 2.

Cordially,

Kerry Thompson
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders