How to Import HTML Text Into Flash

Importing HTML(Hyper Text Markup Language) text directly into your Flash movie allows you to place your existing Web pages into your movie without having to reformat. Besides saving you a lot of time, importing your HTML text will also let you build flash applications that can transform your existing Web pages into movie content. The flash code needed to reformat your web page for your flash movie is not complicated. In fact, once your TextField -- the text box used to store text -- is set up, you just need to attach one simple property.

Things You'll Need

  • Adobe Flash Professional (CS3, CS4, CS5)
Show More

Instructions

    • 1

      Select or create an HTML page to import into your Flash project. Name your HTML file "myhtmltestpage" for this example.

    • 2

      Start your Flash program. Select the "Actions" option from the "Window" menu on the main "Flash" menu bar.

    • 3

      Type the code to declare a "TextField" object in the first line of the "Actions" editor. Use the name "displayText" for the "TextField" object. Type this first line of code as:

      var displayText:TextField = new TextField();

    • 4

      Type the following statements on lines two and three in the "Actions" editor to set the width and height dimensions of the "displayText" TextField to 500 pixels:

      displayText.width = 500;

      displayText.height = 500;

    • 5

      Type the following line in the fourth line of the "Actions" editor to declare an object named "importFile" as a "URLLoader" object, an object that stores a file's contents:

      var importFile:URLLoader = new URLLoader();

    • 6

      Declare a "URLRequest" object -- an object that requests a file to import in the fifth line of the "Actions" editor. Use the name "requestedFile" for the "URLRequest" object. Specify the file name parameter as "myhtmltestpage.html" for the "URLRequest" object. Type the code into the fifth line of the editor as follows:

      var requestedFile: URLRequest = new URLRequest("myhtmltestpage.html");

    • 7

      Instruct the "URLLoader" object to import the HTML file specified in the "URLRequest object (requestedFile)." Type the sixth line of code into the Flash ActionScript code statement as follows:

      importFile.load(requestedFile);

    • 8

      Attach an "Event.Complete" event listener to the loader, "importFile," as part of the "addEventListener" method. Name the event handler called in the "addEventListener" method "htmlloaded_fn." Type this code into the seventh line of the Actions editor:

      importFile.addEventListener(Event.Complete, htmlloaded_fn);

    • 9

      Type the code of the event handler function, "htmlloaded_fn", so that the loaded file's data is placed into the "displayText" text field. Use the "load" data property of the "URLLoader" and the "htmlText" property of the "TextField" object. Type the Flash ActionScript code statements starting at line eight in the "Actions" editor as:

      function htmlloaded_fn(event: Event):

      void {displayText.htmlText = importFile.data;}

    • 10

      Use the "addChild" method with the "displayText" parameter to display the "displayText" "TextField" object. Type the next line of Actions code as "addChild(displayText)."

    • 11

      Select the "Save" option from the "File" menu on the main Flash menu bar. Name the file and save it in the same file directory that your HTML file is saved in.

    • 12

      Select the "TestMovie" option from the "Control" menu on the main Flash menu bar to play the movie and display the HTML rendered text.

Learnify Hub © www.0685.com All Rights Reserved