In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

RGBの値を「0xRRGGBB」表記する

RGBの値を「0xRRGGBB」表記する
Get Adobe Flash player
by ProjectNya 14 Feb 2011

    Talk

    kacchan6 at 12 Feb 2011 10:11
    ロジック間違ってません?10進で文字列化してるし、uint(Math.random()*0xFFFFFF);もuint(Math.random()*0x1000000);じゃないと、0x000000から0xffffffまでの数値が作れないっす。
    ProjectNya at 14 Feb 2011 05:46
    間違ってますね。はい。
    Embed
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cmqM
 */

////////////////////////////////////////////////////////////////////////////////
// RGBの値を「0xRRGGBB」表記する
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;

    [SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var label:Label;

        public function Main() {
            //Wonderfl.capture_delay(1);
            init();
        }

        private function init():void {
            //var rgb:uint = uint(Math.random()*0xFFFFFF);
            var rgb:uint = uint(Math.random()*0x1000000);
            //
            label = new Label(400, 20, 40, Label.CENTER);
            addChild(label);
            label.x = 32;
            label.y = 212;
            label.textColor = 0x000000;
            //label.text = "0x" + ("000000" + rgb).substr(-6);
            label.text = "0x" + ("00000" + rgb.toString(16)).substr(-6).toUpperCase();
        }
        
    }

}


//////////////////////////////////////////////////
// Labelクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;

class Label extends Sprite {
    private var txt:TextField;
    private static var fontType:String = "_ゴシック";
    private var _width:uint = 20;
    private var _height:uint = 20;
    private var size:uint = 12;
    public static const LEFT:String = TextFormatAlign.LEFT;
    public static const CENTER:String = TextFormatAlign.CENTER;
    public static const RIGHT:String = TextFormatAlign.RIGHT;

    public function Label(w:uint, h:uint, s:uint = 12, align:String = LEFT) {
        _width = w;
        _height = h;
        size = s;
        draw(align);
    }

    private function draw(align:String):void {
        txt = new TextField();
        addChild(txt);
        txt.width = _width;
        txt.height = _height;
        txt.autoSize = align;
        txt.type = TextFieldType.DYNAMIC;
        txt.selectable = false;
        //txt.embedFonts = true;
        //txt.antiAliasType = AntiAliasType.ADVANCED;
        var tf:TextFormat = new TextFormat();
        tf.font = fontType;
        tf.size = size;
        tf.align = align;
        txt.defaultTextFormat = tf;
        textColor = 0x000000;
    }
    public function set text(param:String):void {
        txt.text = param;
    }
    public function set textColor(param:uint):void {
        txt.textColor = param;
    }

}