Getting started with FLASH and ASP communication-making your own message book page 1/5

Source: Internet
Author: User

Some people often ask me how to create a FLASH message board. However, I can't make it clear in one sentence, so I came up with the idea of writing a tutorial. Later, I thought about how to teach people to fish. It is better to teach people to fish. It is better to concentrate on the communication principle and principle between FLASH and ASP. The specific project can be used freely.

This tutorial is intended for beginners. Before starting the tutorial, I assume that you have the basic knowledge of FLASH operations and understand IIS configuration and runtime environment. Although there are many communication methods between FLASH and ASP, I chose to use the LoadVars class in this tutorial. One is because the LoadVars class is easy to master and easy to explain, and the other is because it does not involve too much other knowledge. In addition, I use JS scripts in ASP, because JS scripts are very similar to AS. AS long AS you have a certain degree of AS basics, JavaScript can be basically understood without learning. Finally, I chose the FLASH pro 8.0 Simplified Chinese version. swf was released as AS2.0 and flashplayer8.0.

Before reading my tutorial, we recommend that you take a few minutes to read"Basic FLASH development habits", Which is more conducive to understanding my code.

Directory:

  • LoadVars BASICS (LV)
  • Basic Input and Output in ASP
  • Communication principle between LV and ASP
  • ASP database operations
  • Integrated Use of LV and ASP
  • Other communication methods

    Here I will focus on my tutorials. The difference is that there are some full-blown tutorials. I will focus on these two methods and an event: load and loadAndSend methods, and onLoad events. If you want to learn more about the LV class, we suggest you check the help: Help → flash help → all books → reference to the language of ActionScript 2.0 → ActionScript class → LoadVars. You can also search for LoadVars directly.

    LV and TXT Communication.
    Do you want to talk about ASP? How can I start TXT? Haha, don't worry. In fact, the principle of LV and ASP communication is the same as that of TXT communication. TXT files are often used and easy to understand.
    For LV and TXT communication, the "variable"/"value" pair data mode must be used in the TXT file. For example, wenben = I want to prepare a FLASH message book. Here, "wenben" is the variable, "I want to do the FLASH message book" is the value, and "=" is their pairing method, that is, the method of establishing a connection. Now, we have created a “lv_shiyan.txt text file, and input: neirong_txt = I want to prepare a FLASH message book. Create a "lv_shiyan.fla" in the same folder and write the code in the first place:

    // Set the encoding. Otherwise, garbled characters are displayed.
    System. useCodepage = true;
    // Instantiate an LV object
    Var shiyan_lv = new LoadVars ();
    // Load External text
    Shiyan_lv.load ("lv_shiyan.txt ");
    // After Successful loading
    Shiyan_lv.onLoad = function (chenggong ){
    If (chenggong ){
    // Obtain external text content
    Var neirong = shiyan_lv.neirong_txt;
    // Output text content
    Trace ("the content of the text you load is:" + neirong );
    } Else {
    // Prompt for loading failure
    Trace ("loading failed ");
    }
    };

    Run the above Code and you will see in the output panel that the content in "The text you load is: I want to make a flashmessage book, upload it, and upload it externally" has been successfully loaded. If you are interested, you can change the TXT file name and test the loading failure.

    Through the above Code, we learned the following knowledge::
    1. How to instantiate an LV object (using the new keyword)
    2. How to load external text files with LV objects (using the load method)
    3. How to determine whether an external text file is successfully loaded (using the onLoad event)
    4. How to obtain and use the content of an external text file after it is loaded successfully.
    In an external text file, we use the data format of "variable/value" pairs to be used by LV objects. After the external text file is loaded successfully, the variables are recorded by the LV object, and the LV object is referenced by the LV object in the. variable name in an external text file. The above code is shiyan_lv.neirong_txt.

    The above example illustrates the basic principle of LV and TXT communication. Now let's extend it. What if we want to use multiple variables in an external TXT file? The answer is actually very simple. We only need to use multiple "variable/value" pairs in the TXT file and separate each "variable/value" pair. We still use the example lv_shiyan.txt file. This time, we replace the content with the following format:
    Neirongw.txt = beat the LoadVar class! & Amp; neirong2_txt = ASP! & Neirong3_txt = I can make a FLASH message board!
    Then, replace the code in "lv_shiyan.fla" with the following content:

    System. useCodepage = true;
    Var shiyan_lv = new LoadVars ();
    Shiyan_lv.load ("lv_shiyan.txt ");
    Shiyan_lv.onLoad = function (chenggong ){
    If (chenggong ){
    // Obtain external text content
    Var neirong1 = shiyan_lv.neirong1_txt;
    Var neirong2 = shiyan_lv.neirong2_txt;
    Var neirong3 = shiyan_lv.neirong3_txt;
    // Output text content
    Trace ("the content of the text you load is:" + neirong1 + "/" + neirong2 + "/" + neirong3 );
    } Else {
    Trace ("loading failed ");
    }
    };

    Run the above Code. In the output window, we can see the "victory over LoadVar class! /Beat ASP! /I can make a FLASH message board !", This shows that all the variables in the external TXT file are obtained.

    If you are interested, you can change the content in “lv_shiyan.txt to the following format to see if the output results have changed:

    & Amp; neirongw.txt = beat the LoadVar class!
    & Amp; neirong2_txt = ASP!
    & Neirong3_txt = I can make a FLASH message board!
    Then change to the following result and try the output result again :)
    & Amp; neirongw.txt = beat the LoadVar class! &
    & Amp; neirong2_txt = ASP! &
    & Neirong3_txt = I can make a FLASH message board! &
    The reason is actually very simple. Think about it and pull it yourself :)

    The following describes the basic format and syntax of ASP, especially the input and output statements.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.