Using StageWebView

1

I need to implement an Application to display HTML text already formatted, these texts are with images.

I found two options: WebView - But I can not use it as a component, just instantiating and playing on the screen. RichEditableText, this works 100% as I want, however, the ScrollBar does not work on the mobile, and tests on the emulator, works only when scrolling the mouse scroll button

Does anyone know how to solve it?

    
asked by anonymous 05.12.2014 / 13:33

1 answer

1

There are two types of objects for displaying HTML content, the HTMLLoader and the StageWebView .

HTMLLoader

The HTMLLoader object is the most practical to deal with as it works as a container for your HTML elements. You can add it as a child of any other DisplayObjectContainer and more easily manipulate the content that is appearing, including accessing your DOM objects, just as JavaScript does.

Below is a simple code for how content is embedded inside a HTMLLoader object and display it on the stage:

var hl:HTMLLoader = new HTMLLoader(); //Cria o Objeto HTMLLoader
hl.load(new URLRequest("http://www.google.com.br/")); //Carrega o conteúdo HTML, no caso, o site do Google
hl.addEventListener(Event.COMPLETE, completouLoader); //Adiciona o ouvinte COMPLETE

function completouLoader(e:Event):void {
    trace("carregou página");
    hl.width = stage.stageWidth; //Altera o Width e Height do objeto (Por padrão, estes valores possuem 0x0px)
    hl.height = stage.stageHeight;
    addChild(hl); //Adiciona o objeto na tela para exibir a página
}

StageWebView

StageWebView works similar to the above but with features that are limited to ActionScript events and simpler. Not to mention that this object is embedded in the Stage object of your application, which means it will always be above any display object.

Here is a sample sample code:

var wv:StageWebView = new StageWebView(); //Cria o objeto
wv.viewPort = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight); //Configura o tamanho e local de exibição do conteúdo
wv.stage = this.stage; //Atrela ao objeto stage da sua aplicação
wv.loadURL("http://www.google.com.br"); //Carrega o conteúdo do site do Google
wv.addEventListener(Event.COMPLETE, carregou); //Ouvinte de evento Complete
wv.addEventListener(ErrorEvent.ERROR, erro); //Ouvinte de evento Erro

function carregou(e:Event):void {
    trace("Carregou"); //Mais há mais nada a se fazer, após a página carregar toda ação é tomada pelo usuário ou pelos ouvintes disponibilizados pelo objeto "StageWebView"
}

function erro(e:ErrorEvent):void {
    trace("Deu erro.");
    trace(e);
}

These two objects work fine in Flash Professional , but according to the Adobe documentation, they are also compatible with Flex , which in turn has a class called FlexHTMLLoader , which I do not know, but should probably work similar to HTMLLoader .

    
05.12.2014 / 20:21