Highlighted

Canvas containing UIComponent has no scrollbar

Contributor ,
Jan 16, 2019

Copy link to clipboard

Copied

I'm trying to crop part of display object (dispObj). Just cropping width; height is not important.

var ui:UIComponent = cut(dispObj,2000);

var can:Canvas = new Canvas;

can.horizontalScrollPolicy = 'on';

can.addChild(ui);

private function cut(can:DisplayObject,w:int):UIComponent {

     var shapeBitmapData : BitmapData = new BitmapData( w, can.height, true, 0x00000000 );

     shapeBitmapData.draw( can, can.transform.matrix);

     var bm:Bitmap = new Bitmap(shapeBitmapData);

     var ui:UIComponent = new UIComponent;

     ui.addChild(bm);

     return ui;

}

But the final canvas has no horizontal scroll, the ui element is longer than the screen, but canvas don't detect it's content. How else can I crop display objects? Is any simpler way than changing display objects to bitmapData and Bitmap and then uiComponent?

TOPICS
ActionScript

Views

262

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Canvas containing UIComponent has no scrollbar

Contributor ,
Jan 16, 2019

Copy link to clipboard

Copied

I'm trying to crop part of display object (dispObj). Just cropping width; height is not important.

var ui:UIComponent = cut(dispObj,2000);

var can:Canvas = new Canvas;

can.horizontalScrollPolicy = 'on';

can.addChild(ui);

private function cut(can:DisplayObject,w:int):UIComponent {

     var shapeBitmapData : BitmapData = new BitmapData( w, can.height, true, 0x00000000 );

     shapeBitmapData.draw( can, can.transform.matrix);

     var bm:Bitmap = new Bitmap(shapeBitmapData);

     var ui:UIComponent = new UIComponent;

     ui.addChild(bm);

     return ui;

}

But the final canvas has no horizontal scroll, the ui element is longer than the screen, but canvas don't detect it's content. How else can I crop display objects? Is any simpler way than changing display objects to bitmapData and Bitmap and then uiComponent?

TOPICS
ActionScript

Views

263

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 16, 2019 0
LEGEND ,
Jan 16, 2019

Copy link to clipboard

Copied

It is possible the canvas does not automatically adjust when you added content to it dynamically.  Go thru the various methods, both native and inherited to see if there is one that updates/sizes the canvas object after you have added content to it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 16, 2019 0
Contributor ,
Jan 16, 2019

Copy link to clipboard

Copied

Do you mean invalidating stuff? Nothing helps. I've tried:

can.addChild(ui);

can.invalidateSize();

can.invalidateProperties()

can.invalidateDisplayList()

But still no way to scroll. Besides I can see the displayObject on screen.

Strange thing - I made a background for this canvas and it seems the image is not inside? I don't know what to make of it. In this example: https://ibb.co/4sp6j28

blue is canvas and building shapes are the image I put inside canvas. But the canvas is only a scroll bar with no content. How is this even possible...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 16, 2019 0
LEGEND ,
Jan 16, 2019

Copy link to clipboard

Copied

Have you tried using double quotes rather than single quotes for the parameter ...  can.horizontalScrollPolicy = "on";

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 16, 2019 0
Ibarim LATEST
Contributor ,
Jan 17, 2019

Copy link to clipboard

Copied

I've just tried that. No effect. I didn't know single/double quotes make a difference:)

I'll have to cut this displayObject with another canvas. Then I will get scrollBar in outer canvas as it should be.

var canInside:Canvas = new Canvas;

canInside.width = 2000;

canInside.horizontalScrollPolicy = 'off';

canInside.addChild(dispObj);

var canOutside:Canvas = new Canvas;

canOutside.addChild(canInside);

canOutside.width = 1024;

canOutside.horizontalScrollPolicy = "on";

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 17, 2019 0