Adobe Air : StageWebView inside MovieClip

2019-09-08 11:16发布

问题:

I have a simple question. I want to have a StageWebView inside a MovieClip so if the MovieClip is moved, the Stage is moved to.

var view:MovieClip = new MovieClip();
view.y=50;
view.x=10;
view.height=stage.stageHeight-50;
view.width=stage.fullScreenWidth;
addChild(view);

var webView:StageWebView = new StageWebView();

webView=new StageWebView();
webView.stage=view.stage;
webView.viewPort=new Rectangle(0,0,stage.fullScreenWidth,stage.stageHeight);
webView.loadURL("http://www.google.com/");

Even though the "view" mc has a y value of 50 and an x value of 10 the webView is locatet at x:0 and y:0. Of course I could just change the viewPort settings but I really need the WebView to move around with the "view" mc.

Thank you in advance and best regards.

回答1:

It's not on the display list so you can only adjust the position by adjusting the viewPort property.

You could draw the StageWebView to a Bitmap within the MovieClip when you start moving it and then remove the Bitmap and update the StageWebView when the move finishes.

AS3 Docs for drawViewPortToBitmapData()

Edit to provide quick code example:

This code is a bit rough obviously but it should work without any blinking or delays.

dragBar = new Sprite();
addChild(dragBar);
dragBitmap = new Bitmap();
dragBitmap.y = 20;
dragBar.addChild(dragBitmap);
dragBar.graphics.beginFill(0xFF0000);
dragBar.graphics.drawRect(0, 0, 800, 20);
dragBar.x = 20;
dragBar.y = 40;
dragBar.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown)

stageWeb = new StageWebView();
stageWeb.viewPort = new Rectangle(dragBar.x, dragBar.y+20, 800, 600);
stageWeb.stage = stage;
stageWeb.loadURL('http://www.google.co.uk/');

private function handleMouseDown(event:MouseEvent):void
{
    dragBar.startDrag();
    dragBar.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
    var bd:BitmapData = new BitmapData(800, 600);
    stageWeb.drawViewPortToBitmapData(bd);
    dragBitmap.bitmapData = bd;
    stageWeb.stage = null;
}

private function handleMouseUp(event:MouseEvent):void
{
    dragBar.stopDrag();
    dragBar.removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
    dragBitmap.bitmapData = null;
    stageWeb.stage = stage;
    stageWeb.viewPort = new Rectangle(dragBar.x, dragBar.y+20, 800, 600);
}


回答2:

No that's not possible. StageWebView sits on top of and separate to the displaylist. You would have to remove the StageWebView and re-apply it once the movieclip had finished moving.