Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Open html file inside the application

Explorer ,
Jan 15, 2013 Jan 15, 2013

I’m creating some application (Android and IPad) using Flash CS6 (AS3). Want to open some online html (http://www.delta-adv.com/roche/form.php) file inside the application according the specific size which we will set inside the code. For example my application layout size is 1024 x 768 and when I press the button, html file have to open inside the application layout with 800 x 600 size

Is there any possibility to do like this?

TOPICS
ActionScript
6.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 15, 2013 Jan 15, 2013

this is copied from the adobe class files:

package {

    import flash.display.Sprite;

    import flash.html.HTMLLoader;

    import flash.net.URLRequest;

    public class HTMLLoaderExample extends Sprite

    {

        public function HTMLLoaderExample()

        {

            var html:HTMLLoader = new HTMLLoader();

            var urlReq:URLRequest = new URLRequest("http://www.adobe.com/");

            html.width = stage.stageWidth;

            html.height = stage.stageHeight;

            html.load(urlReq);

  

...
Translate
Community Expert ,
Jan 15, 2013 Jan 15, 2013

yes, use the HTMLLoader class.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 15, 2013 Jan 15, 2013

How?? if u dont main can you give me the code.

I hear about UI WEB VIEW.  I don’t know about this can you help me how and which one is the best solution for this

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2013 Jan 15, 2013

this is copied from the adobe class files:

package {

    import flash.display.Sprite;

    import flash.html.HTMLLoader;

    import flash.net.URLRequest;

    public class HTMLLoaderExample extends Sprite

    {

        public function HTMLLoaderExample()

        {

            var html:HTMLLoader = new HTMLLoader();

            var urlReq:URLRequest = new URLRequest("http://www.adobe.com/");

            html.width = stage.stageWidth;

            html.height = stage.stageHeight;

            html.load(urlReq);

            addChild(html);

        }

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 15, 2013 Jan 15, 2013

can i set the size as wll? with required width and height

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2013 Jan 15, 2013

yes, just change html.width and html.height.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 15, 2013 Jan 15, 2013

i try this but got this error

01.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 16, 2013 Jan 16, 2013

Make sure to target AIR in your publishing options.

(Code works for me perfectly targeting AIR 3.4/Desktop.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 17, 2013 Jan 17, 2013

yes boss im publishing in Air for Android

(using Flash CS5.5, i dont have Air 3.4/Destop)

i use this code

package {

    import flash.display.Sprite;

    import flash.html.HTMLLoader;

    import flash.net.URLRequest;

    import flash.display.SimpleButton;

    public class bhtml extends SimpleButton

          {

        public function bhtml()

        {

            var html:HTMLLoader = new HTMLLoader();

            var urlReq:URLRequest = new URLRequest("http://www.adobe.com/");

            html.width = stage.stageWidth;

            html.height = stage.stageHeight;

            html.load(urlReq);

            addChild(html);

        }

    }

}

got the erroer

01.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 17, 2013 Jan 17, 2013

SimpleButton can have no children.

it should say:

public class bhtml extends MovieClip

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 17, 2013 Jan 17, 2013

Now, I didn’t get any error but URL in not opening

package {

    import flash.display.Sprite;

    import flash.html.HTMLLoader;

    import flash.net.URLRequest;

          import flash.display.MovieClip;

    public class bhtml extends MovieClip

          {

        public function bhtml()

        {

            var html:HTMLLoader = new HTMLLoader();

            var urlReq:URLRequest = new URLRequest("http://www.adobe.com/");

            html.width = stage.stageWidth;

            html.height = stage.stageHeight;

            html.load(urlReq);

            addChild(html);

        }

    }

}

01.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 17, 2013 Jan 17, 2013

Where in your main application do you instantiate bhtml?

Is this green rectangle the Button?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 17, 2013 Jan 17, 2013

green rectangel is my movie clip (bhtml). i use my class on this movie clip. i need when i click on this green tectangel my URL have to open... but is not opaning

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 17, 2013 Jan 17, 2013

Make sure that your button is properly exported for Actionscript.

Manual how to do that is here

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 17, 2013 Jan 17, 2013

yes i did

01.jpg

02.jpg

03.jpg

if you dont mind you can also download my file

http://delta-adv.com/nav/02-htmlloader.rar

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 17, 2013 Jan 17, 2013

Base class in image 1 should say:

flash.display.MovieClip

click on the pencil besides class:bhtml to check if the bhtml.as class you wrote is actually linked to the fla (it should be in the same folder as the fla file)

if you click on the pencil and this comes up:

package  {

   

    import flash.display.MovieClip;

   

   

    public class bhtml extends MovieClip {

       

       

        public function bhtml() {

            // constructor code

        }

    }

   

}

then you can be sure that the code you wrote above never reaches your MovieClip.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 17, 2013 Jan 17, 2013

yes when I click on the pencil my bhtml class open (from same folder)

package {

    import flash.display.Sprite;

    import flash.html.HTMLLoader;

    import flash.net.URLRequest;

          import flash.display.MovieClip;

    public class bhtml extends MovieClip

          {

        public function bhtml()

        {

            var html:HTMLLoader = new HTMLLoader();

            var urlReq:URLRequest = new URLRequest("http://www.adobe.com/");

            html.width = stage.stageWidth;

            html.height = stage.stageHeight;

            html.load(urlReq);

            addChild(html);

        }

    }

}


04.jpg

02-b.jpg

My all files in the same directory (.fla and .as)

05.jpg


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 17, 2013 Jan 17, 2013

Good. Then now you have to program the actual behaviour of your button. Because at the moment, your html gets immediately loaded on stage without clicking the button. (at least it does that in my case)

rewrite your bhtml.as like so:

package {

    import flash.display.Sprite;

    import flash.html.HTMLLoader;

    import flash.net.URLRequest;

          import flash.display.MovieClip;

    public class bhtml extends MovieClip

          {

        public function bhtml()

        {

           this.addEventListener(MouseEvent.CLICK, loadHtml);

        }

       public function loadHtml(e:MouseEvent):void{

            trace("CLICKED");

            var html:HTMLLoader = new HTMLLoader();

            var urlReq:URLRequest = new URLRequest("http://www.adobe.com/");

            html.width = stage.stageWidth;

            html.height = stage.stageHeight;

            html.load(urlReq);

           //you don`t want to add the page to the button, but to the stage

            this.parent.addChild(html);

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 17, 2013 Jan 17, 2013

i got this error

01.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 17, 2013 Jan 17, 2013

Here we go:

package

{

    import flash.display.Sprite;

    import flash.html.HTMLLoader;

    import flash.net.URLRequest;

    import flash.display.MovieClip;

    public class bhtml extends MovieClip

    {

        public function bhtml()

        {

            this.addEventListener(MouseEvent.CLICK, loadHtml);

        }

        public function loadHtml(e:MouseEvent):void

        {

            trace("CLICKED");

            var html:HTMLLoader = new HTMLLoader();

            var urlReq:URLRequest = new URLRequest("http://www.adobe.com/");

            html.width = stage.stageWidth;

            html.height = stage.stageHeight;

            html.load(urlReq);

            //you don`t want to add the page to the button, but to the stage

            this.parent.addChild(html);

        }

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 19, 2013 Jan 19, 2013

boss in this time i got this error

01.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 19, 2013 Jan 19, 2013

import flash.events.MouseEvent;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 19, 2013 Jan 19, 2013

now i got this output message, but still URL is not open

01.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 21, 2013 Jan 21, 2013

For testing take a url like google.com that loads quickly. It takes a while depending on your connection.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 01, 2013 Jul 01, 2013
LATEST

thx boss, its work

package  {

    import flash.display.SimpleButton;

          import flash.media.StageWebView;

    import flash.geom.Rectangle;

    import flash.events.KeyboardEvent;

    import flash.ui.Keyboard;

    import flash.desktop.NativeApplication;

          import flash.events.MouseEvent;

               

    public class bclick extends SimpleButton{

        private var webView:StageWebView = new StageWebView();

 

                    public function bclick() {

                              this.addEventListener(MouseEvent.CLICK,clickF);

                              }

                               

        public function clickF(e:MouseEvent):void

        {

            webView.stage = this.stage;

            //webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );

                              webView.viewPort = new Rectangle( 50, 50, 700, 400 );

            webView.loadURL( "http://delta-adv.com/roche/form.php" );

                                               

            stage.addEventListener( KeyboardEvent.KEY_DOWN, onKey );

        }

                               

        private function onKey( event:KeyboardEvent ):void

        {

            if( event.keyCode == Keyboard.BACK && webView.isHistoryBackEnabled )

            {

                trace("Back.");

                webView.historyBack();

                event.preventDefault();

            }

            if( event.keyCode == Keyboard.SEARCH && webView.isHistoryForwardEnabled )

            {

                trace("Forward.");

                webView.historyForward();

            }

        }

    }

}

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