开发者

ActionScript: manually scrolling a element wrapped inside a Scroller window

开发者 https://www.devze.com 2023-03-14 07:34 出处:网络
The answer to my question is possibly easy, yet I haven\'t found an example of solving it in the web, nor have I found a solution reading ActionScript reference.

The answer to my question is possibly easy, yet I haven't found an example of solving it in the web, nor have I found a solution reading ActionScript reference.

My problem is the following: I have a big UIComponent derivate element inside a Scroller (spark.components.Scroller) window. The Scroller class is great because when my canvas element, that changes size dynamically, exceeds its boundaries, scrollbars appear automatically and handle scrolling of my UIComponent inside it.

However, I'd like not just to be able to Scroll using these automatically appeared scroll bars, but also by using a pan tool that I will myself implement (similar to the hand tool in Adobe software, for example). The thing is that I am not able to modify correctly the element's position inside the Scroller window.

I tried, as a first approach, accessing to my elements' 'x' and 'y' properties, however, when changing them, I dont get the resulkts wanted. The code for it is the following (in which, for symplifying reasons, I used a text label as my 'inside' element, and two buttons as an external scroll controller, instead of a hand tool)

Tests.mxml

    <fx:Script>
        <![CDATA[

            protected function der_clickHandler(event:MouseEvent):void
            {
                text.x += 5;

            }

            protected function izq_clickHandler(event:MouseEvent):void
            {
                text.x -= 5;

            }

 开发者_如何转开发       ]]>
    </fx:Script>

    <fx:Declarations>
    </fx:Declarations>
    <s:Scroller id="sc" x="50" y="50" width="200" height="100">
        <s:Group width="100%" height="100%">
            <s:Label id="text" width="400" height="10" x="50" y="50" text="blebleblebleblebleblebleblebleblebleblebleble"/>
        </s:Group>
    </s:Scroller>
    <s:Button id="der" x="154" y="182" label="-&gt;" click="der_clickHandler(event)"/>
    <s:Button id="izq" x="76" y="182" label="&lt;-" click="izq_clickHandler(event)"/>

</s:Application>

And a link to a compiled version, to see what I'm speaking about: http://megaswf.com/file/1135821 (press 'view fullscreen' if you can't see it)

Help would be really appreciated, as I've been stuck all afternoon with this, and really need it for my project :S

Anyway, many thanks in advance, and regards!


I managed to solve it! (This is the second time this week that I solve something just after posting it here :D).

The property that I had to change is sc.viewport.horizontalScrollPosition+=5; instead of the internal elements 'x' position. And the same for vertical pos.

0

精彩评论

暂无评论...
验证码 换一张
取 消