Whats in 127?

While in AS3 the new alpha values are from “0.0” to “1.0”, there is really something happening under the hood,if one increases it beyond 1. Tried to trace out alpha while increasing it by one on each frame. To my surprise it goes on increasing,well the real surprise came out when the value suddenly goes back to negative. So it goes like this,from 0 to 127 and then from -128 to 0 and goes on like that. Thought it would be helpful to someone who might be trying to play with alpha and think his/her code not working correct.

Testing code

this.addEventListener(Event.ENTER_FRAME,checkOnEachFrame);
private function checkOnEachFrame(e:Event):void
{
this.s.alpha += 1;
trace(this,’alpha is ‘+this.s.alpha);
}

The result is

[object Main] alpha is 2
[object Main] alpha is 3
[object Main] alpha is 4
[object Main] alpha is 5
[object Main] alpha is 6
[object Main] alpha is 7
[object Main] alpha is 8
[object Main] alpha is 9
[object Main] alpha is 10
[object Main] alpha is 11
[object Main] alpha is 12
[object Main] alpha is 13
[object Main] alpha is 14
[object Main] alpha is 15
[object Main] alpha is 16
[object Main] alpha is 17
[object Main] alpha is 18
[object Main] alpha is 19
[object Main] alpha is 20
[object Main] alpha is 21
[object Main] alpha is 22
[object Main] alpha is 23
[object Main] alpha is 24
[object Main] alpha is 25
[object Main] alpha is 26
[object Main] alpha is 27
[object Main] alpha is 28
[object Main] alpha is 29
[object Main] alpha is 30
[object Main] alpha is 31
[object Main] alpha is 32
[object Main] alpha is 33
[object Main] alpha is 34
[object Main] alpha is 35
[object Main] alpha is 36
[object Main] alpha is 37
[object Main] alpha is 38
[object Main] alpha is 39
[object Main] alpha is 40
[object Main] alpha is 41
[object Main] alpha is 42
[object Main] alpha is 43
[object Main] alpha is 44
[object Main] alpha is 45
[object Main] alpha is 46
[object Main] alpha is 47
[object Main] alpha is 48
[object Main] alpha is 49
[object Main] alpha is 50
[object Main] alpha is 51
[object Main] alpha is 52
[object Main] alpha is 53
[object Main] alpha is 54
[object Main] alpha is 55
[object Main] alpha is 56
[object Main] alpha is 57
[object Main] alpha is 58
[object Main] alpha is 59
[object Main] alpha is 60
[object Main] alpha is 61
[object Main] alpha is 62
[object Main] alpha is 63
[object Main] alpha is 64
[object Main] alpha is 65
[object Main] alpha is 66
[object Main] alpha is 67
[object Main] alpha is 68
[object Main] alpha is 69
[object Main] alpha is 70
[object Main] alpha is 71
[object Main] alpha is 72
[object Main] alpha is 73
[object Main] alpha is 74
[object Main] alpha is 75
[object Main] alpha is 76
[object Main] alpha is 77
[object Main] alpha is 78
[object Main] alpha is 79
[object Main] alpha is 80
[object Main] alpha is 81
[object Main] alpha is 82
[object Main] alpha is 83
[object Main] alpha is 84
[object Main] alpha is 85
[object Main] alpha is 86
[object Main] alpha is 87
[object Main] alpha is 88
[object Main] alpha is 89
[object Main] alpha is 90
[object Main] alpha is 91
[object Main] alpha is 92
[object Main] alpha is 93
[object Main] alpha is 94
[object Main] alpha is 95
[object Main] alpha is 96
[object Main] alpha is 97
[object Main] alpha is 98
[object Main] alpha is 99
[object Main] alpha is 100
[object Main] alpha is 101
[object Main] alpha is 102
[object Main] alpha is 103
[object Main] alpha is 104
[object Main] alpha is 105
[object Main] alpha is 106
[object Main] alpha is 107
[object Main] alpha is 108
[object Main] alpha is 109
[object Main] alpha is 110
[object Main] alpha is 111
[object Main] alpha is 112
[object Main] alpha is 113
[object Main] alpha is 114
[object Main] alpha is 115
[object Main] alpha is 116
[object Main] alpha is 117
[object Main] alpha is 118
[object Main] alpha is 119
[object Main] alpha is 120
[object Main] alpha is 121
[object Main] alpha is 122
[object Main] alpha is 123
[object Main] alpha is 124
[object Main] alpha is 125
[object Main] alpha is 126
[object Main] alpha is 127
[object Main] alpha is -128
[object Main] alpha is -127
[object Main] alpha is -126
[object Main] alpha is -125
[object Main] alpha is -124
[object Main] alpha is -123
[object Main] alpha is -122
[object Main] alpha is -121
[object Main] alpha is -120
[object Main] alpha is -119
[object Main] alpha is -118
[object Main] alpha is -117
[object Main] alpha is -116
[object Main] alpha is -115
[object Main] alpha is -114
[object Main] alpha is -113
[object Main] alpha is -112
[object Main] alpha is -111
[object Main] alpha is -110
[object Main] alpha is -109
[object Main] alpha is -108
[object Main] alpha is -107
[object Main] alpha is -106
[object Main] alpha is -105
[object Main] alpha is -104
[object Main] alpha is -103
[object Main] alpha is -102
[object Main] alpha is -101
[object Main] alpha is -100
[object Main] alpha is -99
[object Main] alpha is -98
[object Main] alpha is -97
[object Main] alpha is -96
[object Main] alpha is -95
[object Main] alpha is -94
[object Main] alpha is -93
[object Main] alpha is -92
[object Main] alpha is -91
[object Main] alpha is -90
[object Main] alpha is -89
[object Main] alpha is -88
[object Main] alpha is -87
[object Main] alpha is -86
[object Main] alpha is -85
[object Main] alpha is -84
[object Main] alpha is -83
[object Main] alpha is -82
[object Main] alpha is -81
[object Main] alpha is -80
[object Main] alpha is -79
[object Main] alpha is -78
[object Main] alpha is -77
[object Main] alpha is -76
[object Main] alpha is -75
[object Main] alpha is -74
[object Main] alpha is -73
[object Main] alpha is -72
[object Main] alpha is -71
[object Main] alpha is -70
[object Main] alpha is -69
[object Main] alpha is -68
[object Main] alpha is -67
[object Main] alpha is -66
[object Main] alpha is -65
[object Main] alpha is -64
[object Main] alpha is -63
[object Main] alpha is -62
[object Main] alpha is -61
[object Main] alpha is -60
[object Main] alpha is -59
[object Main] alpha is -58
[object Main] alpha is -57
[object Main] alpha is -56
[object Main] alpha is -55
[object Main] alpha is -54
[object Main] alpha is -53
[object Main] alpha is -52
[object Main] alpha is -51
[object Main] alpha is -50
[object Main] alpha is -49
[object Main] alpha is -48
[object Main] alpha is -47
[object Main] alpha is -46
[object Main] alpha is -45
[object Main] alpha is -44
[object Main] alpha is -43
[object Main] alpha is -42
[object Main] alpha is -41
[object Main] alpha is -40
[object Main] alpha is -39
[object Main] alpha is -38
[object Main] alpha is -37
[object Main] alpha is -36
[object Main] alpha is -35
[object Main] alpha is -34
[object Main] alpha is -33
[object Main] alpha is -32
[object Main] alpha is -31
[object Main] alpha is -30
[object Main] alpha is -29
[object Main] alpha is -28
[object Main] alpha is -27
[object Main] alpha is -26
[object Main] alpha is -25
[object Main] alpha is -24
[object Main] alpha is -23
[object Main] alpha is -22
[object Main] alpha is -21
[object Main] alpha is -20
[object Main] alpha is -19
[object Main] alpha is -18
[object Main] alpha is -17
[object Main] alpha is -16
[object Main] alpha is -15
[object Main] alpha is -14
[object Main] alpha is -13
[object Main] alpha is -12
[object Main] alpha is -11
[object Main] alpha is -10
[object Main] alpha is -9
[object Main] alpha is -8
[object Main] alpha is -7
[object Main] alpha is -6
[object Main] alpha is -5
[object Main] alpha is -4
[object Main] alpha is -3
[object Main] alpha is -2
[object Main] alpha is -1
[object Main] alpha is 0
[object Main] alpha is 1
[object Main] alpha is 2
[object Main] alpha is 3
[object Main] alpha is 4
[object Main] alpha is 5
[object Main] alpha is 6
[object Main] alpha is 7
[object Main] alpha is 8
[object Main] alpha is 9
[object Main] alpha is 10
[object Main] alpha is 11
[object Main] alpha is 12
[object Main] alpha is 13
[object Main] alpha is 14
[object Main] alpha is 15
[object Main] alpha is 16
[object Main] alpha is 17
[object Main] alpha is 18
[object Main] alpha is 19
[object Main] alpha is 20
[object Main] alpha is 21
[object Main] alpha is 22
[object Main] alpha is 23
[object Main] alpha is 24
[object Main] alpha is 25
[object Main] alpha is 26
[object Main] alpha is 27
[object Main] alpha is 28
[object Main] alpha is 29
[object Main] alpha is 30
[object Main] alpha is 31
[object Main] alpha is 32
[object Main] alpha is 33
[object Main] alpha is 34

Advertisements

Author: saumya

designer / developer / maker / educator @saumya

3 thoughts on “Whats in 127?”

  1. Looks like we’d better make sure the values we assign to alpha values are clamped between 0.0 and 1.0, otherwise, according to your result, incrementing alpha values constantly might cause display objects to “blink”!

  2. Interesting observation. But let us not forget: It is sometimes usefull not to clamp alpha values between 0.0 and 1.0!

    One can make “transitions” and easing-effects by just assigning different alpha values to sprites and then change the alpha value of their parent. A child with starting alpha 10 will not visually fade before parent has reached alpha 0.1 (or so I believe).

    When trying to fade complex sprites (sprites with many children/shapes) the result can be messy. Setting high alphas for some of the children may help to control unwanted effects.

    package
    {
    import flash.display.Sprite;
    import flash.events.Event;

    public class AlphaTest extends Sprite
    {

    public function AlphaTest ()
    {
    var spr:Sprite;
    for ( var i:uint = 0; i < 10; i++ )
    {
    spr = new Sprite();
    spr.alpha = i;
    spr.graphics.beginFill( 0xff0000 );
    spr.graphics.drawCircle( i * 40 + 30, 300, 20 );
    addChild ( spr );
    }

    addEventListener( Event.ENTER_FRAME, enterFrameHandler );
    }

    private function enterFrameHandler ( e:Event ):void
    {
    alpha -= 0.01;

    if ( alpha <= 0 ) removeEventListener( Event.ENTER_FRAME, enterFrameHandler );
    }
    }
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s