List with custom ScrollBar

The Application:

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    creationComplete="init()"
    xmlns:controls="com.mariosh.controls.*" viewSourceURL="srcview/index.html">

    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            []

            private var ac:ArrayCollection;

            private function init():void
            {
                ac = new ArrayCollection();
                for(var i:int=0; i<30; i++)
                {
                    var item:Object = new Object();
                    item.label = "item " + i;
                    ac.addItem(item);
                }
            }

        ]]>
    </mx:Script>
    <controls:BasicList
        x="10"
        y="10"
        width="100"
        height="200"
        dataProvider="{ac}"
        verticalScrollPolicy="off"/>
</mx:Application>

BasicList.as

package com.mariosh.controls

{
    import flash.events.Event;

    import mx.controls.List;

    public class BasicList extends List

    {
        private var scrollbar:ScrollBar;

        public function BasicList()

        {
            super();
        }

        override protected function createChildren():void

        {
            super.createChildren();

            if(!scrollbar)
            {

                scrollbar = new ScrollBar();
                scrollbar.addEventListener(Event.CHANGE, thumbChange);
                addChild(scrollbar);
            }

        }

        private function thumbChange(event:Event):void

        {
            var listIndex:int = scrollbar.scrollPercentage *(this.dataProvider.length - 9);
            this.verticalScrollPosition = listIndex;
        }

        override protected function commitProperties():void
        {
            super.commitProperties();

            scrollbar.width = 10;
            scrollbar.height = this.height;
            this.verticalScrollPosition = 10;
        }

        override protected function updateDisplayList(uW:Number, uH:Number):void

        {
            super.updateDisplayList(uW, uH);

            scrollbar.move(uW-scrollbar.width, 0);
        }

    }
}

ScrollBar.as

package com.mariosh.controls
{
    import flash.events.Event;
    import flash.events.MouseEvent;

    import mx.core.UIComponent;

    [(name="change", type="flash.events.Event")]

    public class ScrollBar extends UIComponent
    {
        private var track:Track;
        private var thumb:Thumb;

        private var _yOffset:Number;
        private var _yMin:Number = 0;
        private var _yMax:Number;

        public function ScrollBar()
        {
            super();
        }

        private function thumbDown(event:MouseEvent):void
        {
            stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
            stage.addEventListener(MouseEvent.MOUSE_UP, thumbUp);
            _yOffset = this.mouseY - thumb.y;
        }

        private function thumbUp(event:MouseEvent):void
        {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
            stage.removeEventListener(MouseEvent.MOUSE_UP, thumbUp);
        }

        private function thumbMove(event:MouseEvent):void
        {
            thumb.y = this.mouseY - _yOffset;
             if(thumb.y <= _yMin)

                thumb.y = 0;
            if(thumb.y >= _yMax)

                thumb.y = _yMax; 

            _sp = thumb.y / _yMax;

            dispatchEvent(new Event(Event.CHANGE));

            event.updateAfterEvent();
        }

        private var _sp:Number;
        public function get scrollPercentage():Number

        {
            return _sp;
        }

        //--------------------------------------------
        // override methods
        //--------------------------------------------
        override protected function createChildren():void

        {
            super.createChildren();

            if(!track)
            {

                track = new Track();
                track.width = 10;
                addChild(track);
            }

            if(!thumb)
            {
                thumb = new Thumb();
                thumb.width = 10;
                thumb.height = 40;
                thumb.addEventListener(MouseEvent.MOUSE_DOWN, thumbDown);
                addChild(thumb);
            }

        }

        override protected function commitProperties():void
        {

            super.commitProperties();

            track.height = this.height;
            _yMax = track.height - thumb.height;
        }

    }
}

Track.as

package com.mariosh.controls

{
    import mx.core.UIComponent;

    public class Track extends UIComponent

    {
        public function Track()
        {
            super();
        }

        override protected function updateDisplayList(uW:Number, uH:Number):void

        {
            super.updateDisplayList(uW, uH);

            graphics.clear();
            graphics.beginFill(0x333333);
            graphics.drawRect(0, 0, uW, uH);
            graphics.endFill();
        }

    }
}

Thumb.as

package com.mariosh.controls

{
    import mx.core.UIComponent;

    public class Thumb extends UIComponent

    {
        public function Thumb()
        {
            super();
        }

        override protected function updateDisplayList(uW:Number, uH:Number):void

        {
            super.updateDisplayList(uW, uH);

            graphics.clear();
            graphics.beginFill(0x666666);
            graphics.drawRect(0, 0, uW, uH);
            graphics.endFill();
        }

    }
}

Leave a comment

Alice Gomez With Madalyn Blanchett and Marilyn Rife song downloads Angra new mp3 Chris Hinze and Gyuto Monks music to download City Boy song downloads Curtis Mayfield-The Impressions mp3 music Dere album Jack Dejohnette - Pat Metheny - Herbie Hancock - Dave Holland buy mp3 John Acquaviva and Madox Ft Tommie Sunshine mp3 downloads Leon Tomas music Love Spirals Downwards music macka b and the royale roots band mp3s Melodica music Michail Anthimos Dissos all mp3 oceanlab featuring justine suissa mp3 search Pat Monahan album Peter Cincotti mp3 music Planet P Project mp3 Sly and Robbie mp3 online Straight Outta Junior High english mp3 Vibrasphere downloadable music 18 Summers mp3 downloads Alexi Delano and Tony Rohr song downloads Alicja Janosz english mp3 Arrested Development download David Amo And Julio Navas Vs Maw mp3 songs Dresden Dolls new mp3 Forgotten Woods music Foxhole best mp3 Ictus mp3 downloads Igor S VS Lady Brian instrumental Ina Deter song downloads Jan Garbarek - Ustad Fateh Ali Khan new mp3 John Travolta get mp3 Jorge Palma review Kyaw Kyaw Naing best mp3 Laika mp3s Octex get mp3 Pete Johnson mp3 search Rocio Durcal download Santa Geracao 11 downloads Silent Voices music search Slagerij Van Kampen mp3 search Stadio download mp3 Steve Angello mp3 song Welladay pop Accused download mp3 Barkays VS Double Dose downloadable music Blind Dog downloads Cafe Quijano music download Calibre top mp3 Crowbar mp3 downloads Dies Ater mp3 online Dosh download songs Feelies album Good For Cows dowland James Yorkston music search Jan Garbarek and Gary Peacock downloads Jive Bunnys mp3 songs Last Resort mp3 music Liberto and Mihalis Safras music downloading Marisa Monte downloadable music Night of the Brain all mp3 Nishat Khan downloads Rezerection download mp3 Robin Williamson and Mike Heron mp3 songs Satriani, Malmsteen, Vai mp3 downloads Sengir downloads Squad 21 instrumental Swingle Singers And Modern Jazz Quartet top mp3 Waylon Jennings mp3 online Aceyalone top mp3 Afrika Bambaataa mp3 online Akcent pop Ancient Winds music downloading Anthropolatri albums Dave Ellesmere and Polder pop Dizzy Mizz Lizzy music to download Dreams Of Sanity dowland God Dethroned song downloads Grendel best mp3 Jacka And Lee Majors instrumental Jessica Williams download songs Kevin Rudolf dowland La Petite Bande, con. Gustav Leonhardt top mp3 Little Wolf Band mp3 online Nautilis mp3 song Night in Gales music Orkiestra Osmego Dnia dowland Outlines mp3 song Popa Chubby download mp3 Radiation 4 mp3 song Smash TV mp3 search Sorin Pavelescu albums Tatsuhiko Asano all mp3 Tom Russell music download Ustad Imrat Khan and his sons review Usura song downloads Waterdown new mp3 Wendy James albums Xenomorph get mp3