scrollRect width and height?


#1

Hello,

I try to use scrollRect

package;

import com.SpriteMask;
import flash.display.Sprite;
import flash.events.MouseEvent;

class Main extends Sprite
{
    private var spriteMask:SpriteMask = new SpriteMask();

    public function new()
    {
        super();
        
        spriteMask.graphics.beginFill(0x0000FF);
        spriteMask.graphics.drawRect( 0, 0, 200, 200);
        spriteMask.graphics.endFill();
        spriteMask.buttonMode = true;
        spriteMask.addEventListener(MouseEvent.CLICK, mouseClickOutsideHandler);
        this.addChild( spriteMask );
    }

    private function mouseClickOutsideHandler(event:MouseEvent):Void
    {
        trace( spriteMask.width, spriteMask.height );
    }
}

and

package com;

import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Rectangle;

class SpriteMask extends Sprite
{
    public function new()
    {
        super();
        
        this.scrollRect = new Rectangle( 0, 0, 100, 100);
        
        var sprite:Sprite = new Sprite();
        sprite.graphics.beginFill(0xFF0000);
        sprite.graphics.drawRect( 0, 0, 200, 200);
        sprite.graphics.endFill();
        this.addChild(sprite);
    }
}

but spriteMask.width, spriteMask.height return 200, 200 and not 100, 100 ?

thanks


#2

Yes, I think that the sprite.width and height return the logical size, not the visual size, as based on the scrollRect object.

However, please feel free to openfl test flash as well, and see if you get the same results. If not, it’s probably a bug


#3

using Flash spriteMask.width, spriteMask.height return the visual size 100, 100 in next frame and not 200, 200 like OpenFl html5
to get the logical size, I use spriteMask.transform.pixelBounds.width and spriteMask.transform.pixelBounds.height (200, 200) in Flash, return (0, 0) in OpenFl html5


#4

Oh, fun… next frame? So Flash returns 200 for the size in the same frame, but 100 when going to the next one?


#5

Flex use scrollRect, scrollRect is uptaded in next frame, it’s necessary to use callLater() in some times.


#6

Okay, I’ve opened an issue here: https://github.com/openfl/openfl/issues/2136