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

Custom ScrollPane

Also, custom button, custom scrollbar
Get Adobe Flash player
by angelhdz12 26 Apr 2015
    Embed
/**
 * Copyright angelhdz12 ( http://wonderfl.net/user/angelhdz12 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/w4XT
 */

package {
    import flash.display.SimpleButton;
    import flash.text.TextFormat;
    import flash.text.TextField;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.MouseEvent;

    public class FlashTest extends Sprite 
    {            
        private var mc:MovieClip = new MovieClip();
        private var sp:ScrollPane = new ScrollPane();
        public static var txt:TextField = new TextField();
        private var count:int;
        private var tfmt:TextFormat = new TextFormat();
 
        public function FlashTest() 
        {
            // write as3 code here..
            addChild(txt);
            txt.y = 300;
            sp.x = 10;
            sp.source = mc;
            addChild(sp);
            tfmt.font = "Tahoma";
            tfmt.size = 12;
            var tf:TextField = new TextField();
            tf.type = "input";
            tf.multiline = false;
            tf.border = true;
            tf.defaultTextFormat = tfmt;
            tf.width = 100;
            tf.height = tf.textHeight + 4;
            tf.y = 290 - tf.height;
            tf.text = "0xff0000";

            addChild(tf);
            var btn:Button = new Button();
            btn.y = 300;
            btn.label = "Add";

            btn.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void
            {
                var s:Sprite = new Sprite();
                s.graphics.beginFill(uint(tf.text));
                s.graphics.drawRect(0, 0, 200, 30);
                s.y = count * (s.height + 2);
                count++;
                mc.addChild(s);
                sp.update();
            });
            addChild(btn);
        }
       
        public static function trace(...rest):void
        {
            for(var i:* in rest)
            {
                txt.appendText(rest[i])
            }
            txt.appendText("\n");
        }
    }
}

//ScrollPane************************************************
import flash.text.TextField;
import flash.filters.DropShadowFilter;
import flash.display.MovieClip;

class ScrollPane extends MovieClip
{
    private var _source:MovieClip;
    private var mc:MovieClip;
    private var sb:ScrollBar;
    private var _scrollPosition:Number;

    public function ScrollPane()
    {
        graphics.beginFill(0xffffff);
        graphics.drawRect(0, 0, 200, 150);   
        mc = new MovieClip();
        mc.graphics.beginFill(0x000000);
        mc.graphics.drawRect(0, 0, 200, 150);
        addChild(mc); 
        var shadow:DropShadowFilter = new DropShadowFilter();
        shadow.blurX = shadow.blurY = 5;
        shadow.color = 0x000000;
        shadow.angle = 90;
        shadow.distance = 3;
        shadow.alpha = 0.6;
        filters = [shadow];
        sb = new ScrollBar();
        sb.x = 200;
        addChild(sb);
        sb.visible = false;
    }
    
    public function get maxScrollPosition():Number
    {
        return (mc.height - _source.height);
    }
    
    public function set scrollPosition(scrollPosition:Number):void
    {
        _scrollPosition = scrollPosition;
        
        if(_source.height > mc.height)
        {
            _source.y = maxScrollPosition;
        }
    }
    
    public function get scrollPosition():Number
    {
        return _scrollPosition;
    }

    public function set source(source:MovieClip):void
    {
        _source = source;
        addChild(_source);
        _source.mask = mc;
    }
    
    public function get source():MovieClip
    {
        return _source;
    } 
    
    public function update():void
    {
        scrollPosition = maxScrollPosition;
        checkScroll();
    }
    
    private function checkScroll():void
    {        
        if(_source.height > mc.height)
        {
            sb.visible = true;
        }
        else
        {
            sb.visible = false;
        }
    }
}

//ScrollBar************************************************

/*Coming soon:
- Up and down buttons/arrows
- Draggable scroll thumb
- Mouse scroll
*/
class ScrollBar extends MovieClip
{
    public function ScrollBar()
    {
        graphics.beginFill(0x666666);
        graphics.drawRect(0, 0, 20, 150);
    } 
}

//Button************************************************
import flash.display.SimpleButton;
import flash.geom.Matrix; 
import flash.text.TextFormat;

class Button extends SimpleButton
{
    private var _label:String;
    private var tf:TextField;
    private var tfmt:TextFormat = new TextFormat();
    
    public function Button()
    {                 
        tfmt.font = "Tahoma";
        tfmt.size = 12;
        upState = draw(0x999999, [0xffffff, 0x999999]);
        hitTestState = draw(0x999999, [0xffffff, 0x999999]);
        overState = draw(0x00ccff, [0xffffff, 0x999999]);
        downState = draw(0x00ccff, [0x00ccffff, 0x00ccff]);
    }
    
    public function set label(label:String):void
    {
        _label = label;
        var states:Array = [upState, overState, downState];
        
        for(var i:* in states)
        {
            var txt:TextField = TextField(states[i].getChildAt(0));
            txt.text = _label;
        }
    }

    
    private function draw(_lineColor:uint, _gradient:Array):MovieClip
    {
        var btn:MovieClip = new MovieClip();
        var matrix:Matrix = new Matrix(); 
        var boxWidth:Number = 50; 
        var boxHeight:Number = 50; 
        var boxRotation:Number = Math.PI/2; // 90° 
        var tx:Number = 25; 
        var ty:Number = 0; 
        matrix.createGradientBox(boxWidth, boxHeight, boxRotation, tx, ty); 
        btn.graphics.lineStyle(1, _lineColor);
        btn.graphics.beginGradientFill("linear", _gradient, [1, 1], [0, 255],matrix, "pad", "linearRGB", 0); 
        btn.graphics.drawRect(0, 0, 100, 22);
        
        tf = new TextField();
        tf.defaultTextFormat = tfmt;
        tf.autoSize = "left";
        tf.text = "Label";
        tf.x = btn.width/2 - tf.width /2;
        tf.y = btn.height/2 - tf.height/2
        btn.addChild(tf);
        return btn;
    }
}