Skip navigation
Currently Being Moderated

Transparent ScrollBar for Scroller

Feb 25, 2010 12:34 PM

Hi,

 

I need to figure it out, how to have semi-transparent track for VScrollBar. content behind Scrollbar should be visible. When I have skinned Scorrlbar and set alpha to track, it doesnt work, when I have set alpha to s:Scroller, whole content was semiTransparent, so I dont how to do that. Is it possible?

 

thanks

 
Replies
  • Currently Being Moderated
    Feb 25, 2010 1:37 PM   in reply to franto kormanak

    Hi,

     

    Do you mind attaching a test case? I would assume setting the alpha on the track should work as long as the Scroller points to that specific skin in its skin.

     

    Thanks,

    -Kevin

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2010 2:56 PM   in reply to franto kormanak

    Beta 2? *gasp*

    You should update to a new nightly build, ASAP. http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4

     

    I managed to get a semi-transparent VScrollBar track in Flex 4 Scroller by creating a custom VScrollBar skin and setting the skinClass style using CSS.

     

    Main app:

     

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   backgroundColor="red">
        <s:controlBarContent>
            <s:Label id="sdkVer" initialize="sdkVer.text = mx_internal::VERSION + ' | ' + Capabilities.version;" />
        </s:controlBarContent>
       
        <fx:Style>
            @namespace s "library://ns.adobe.com/flex/spark";
            @namespace mx "library://ns.adobe.com/flex/mx";
           
            s|Scroller s|VScrollBar {
                skinClass: ClassReference("skins.TransVSB");
            }
        </fx:Style>
       
        <s:Scroller width="500" height="400">
            <s:Group>
                <s:TextArea text="The quick brown fox jumps over the lazy dog." height="900" width="90%" />
            </s:Group>
        </s:Scroller>
       
    </s:Application>

     

     

    And my custom VScrollBar skin, skins/TransVSB.mxml, is as follows:

     

    <?xml version="1.0" encoding="utf-8"?>
    <s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
                 xmlns:s="library://ns.adobe.com/flex/spark"
                 xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
                 minWidth="15" minHeight="35"
                 alpha.disabled="0.5"
                 alpha.inactive="0.5" >
       
        <fx:Metadata>
            [HostComponent("spark.components.VScrollBar")]
        </fx:Metadata>
       
        <fx:Script fb:purpose="styling">
            /* Define the skin elements that should not be colorized.
            For scroll bar, the skin itself is colorized but the individual parts are not. */
            static private const exclusions:Array = ["track", "thumb", "decrementButton", "incrementButton"];
           
            override public function get colorizeExclusions():Array {
                return exclusions;
            }
           
            override protected function initializationComplete():void {
                useChromeColor = true;
                super.initializationComplete();
            }
        </fx:Script>
       
        <s:states>
            <s:State name="normal" />
            <s:State name="disabled" />
            <s:State name="inactive" />
        </s:states>
       
        <!---  The default skin class is VScrollBarTrackSkin. -->
        <s:Button id="track" top="16" bottom="15" height="54"
                  focusEnabled="false"
                  alpha="0.2"
                  skinClass="spark.skins.spark.VScrollBarTrackSkin" />
       
        <!--- The default skin class is VScrollBarThumbSkin. -->
        <s:Button id="thumb"
                  focusEnabled="false" visible.inactive="false"
                  skinClass="spark.skins.spark.VScrollBarThumbSkin" />
       
        <!--- The default skin class is ScrollBarUpButtonSkin. -->
        <s:Button id="decrementButton" top="0" enabled.inactive="false"
                  focusEnabled="false"
                  skinClass="spark.skins.spark.ScrollBarUpButtonSkin" />
       
        <!---  The default skin class is ScrollBarDownButtonSkin. -->
        <s:Button id="incrementButton" bottom="0" enabled.inactive="false"
                  focusEnabled="false"
                  skinClass="spark.skins.spark.ScrollBarDownButtonSkin" />
       
    </s:SparkSkin>

     

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2010 3:02 PM   in reply to Peter deHaan

    Or you could try setting it via ActionScript and no custom skin needed.

     

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   backgroundColor="red">
        <s:controlBarContent>
            <s:HSlider id="sl"
                       minimum="0.0" maximum="1.0"
                       value="1.0"
                       snapInterval="0.1" stepSize="0.1"
                       change="sl_changeHandler(event)" />
            <s:Label id="sdkVer" initialize="sdkVer.text = mx_internal::VERSION + ' | ' + Capabilities.version;" />
        </s:controlBarContent>
       
        <fx:Script>
            <![CDATA[
                protected function sl_changeHandler(evt:Event):void {
                    scrllr.verticalScrollBar.track.alpha = sl.value;
                }
            ]]>
        </fx:Script>
       
        <s:Scroller id="scrllr" width="500" height="400">
            <s:Group>
                <s:Rect width="100%" height="900">
                    <s:fill>
                        <s:LinearGradient rotation="45">
                            <s:GradientEntry color="red" />
                            <s:GradientEntry color="haloGreen" />
                            <s:GradientEntry color="haloBlue" />
                        </s:LinearGradient>
                    </s:fill>
                </s:Rect>
            </s:Group>
        </s:Scroller>
       
    </s:Application>

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2010 8:50 PM   in reply to Peter deHaan

    @ Peter

     

    Very nice elegant solution indeed.

    Thank you, Peter.

     

    However there is one strange inconsistency:

    if I add to the function two other elements -

     

    scrllr.verticalScrollBar.thumb.alpha = sl.value;

    scrllr.verticalScrollBar.incrementButton.alpha = sl.value;

     

    the thumb and the bottom incrementButton are changing their transparency, but the top incrementButton completely ignores the change - it stays completely opaque.

     

    Any particular reasons for that?

     

    Thanks,

    FTQuest

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2010 9:53 PM   in reply to FTQuest

    @FTQuest,

     

    Sure, the top one is the decrementButton skin part. The incrementButton is the bottom button.

     

    protected function sl_changeHandler(evt:Event):void {

        scrllr.verticalScrollBar.track.alpha = sl.value;

        scrllr.verticalScrollBar.incrementButton.alpha = sl.value;

        scrllr.verticalScrollBar.decrementButton.alpha = sl.value;

    }

     

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2010 9:15 AM   in reply to Peter deHaan

    @Peter

    Oh, boy!

    Thank you, Peter.

    FTQuest

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2010 10:05 AM   in reply to franto kormanak

    @franto,

     

    I dont know of a way off the top of my head, but I'm not a Scroller expert.

    I tried setting the "right" property on the verticalScrollBar but that didnt seem to work. The only other idea I had was to disable horizontal and vertical scrollbars on the Scroller altogether and use your own s:VScrollBar in the main app and just position it over the Scroller wherever you want (you could just wrap the Scroller and VScrollBar in a s:Group container or something).

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 7, 2010 1:16 PM   in reply to franto kormanak

    Regarding moving the position of scrollbars in a Scroller:

     

    You can't reposition the scrollbars that are inside of a Scroller.  Scroller uses its own layout algorithm to position the scrollbars (in order to support auto scroll policies).

     

    Scroller is designed not to be re-skinned beyond changing the skin of its VScrollBar and HScrollBar.  Just like franto kormanak did above, if you would like to move scrollbars around you are encouraged to hook up your own VScrollBar/HScrollBar instead of using a Scroller.  See http://flexponential.com/2009/10/09/changing-the-position-of-the-scrol l-bars-in-a-spark-list/ for an example.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points