The following example is the "Hello World" example. We will be sending a simple string to display in Flash. The first step is to create the ASP page, so here is the code:
<%@Language=VBScript%> <%Option Explicit%> <% Response.Write("Hello World!!") %>
If you were to test this script right now in a browser, it would display the text as it is, but from the previous chapter you learned that Flash will need this data in name/value pair format. So change the Response.Write line to the following:
Save the script as helloWorld.asp and put it on the server. Next up is the Flash part, so open Flash and follow these steps:
The first thing that happens in the preceding code is that a text field is created to display the message being returned. Next up is the LoadVars object, which will connect to the ASP page to get the message. After that, we set up the onLoad event callback for when the data is received. In it, we pass the parameter success to make sure there were no problems connecting to the ASP page. If success is true, the message is displayed in the text field we created; if not, an error is sent to the Output panel. Finally, we call the load method to get the data by passing it the full path to ASP page. If you were to put this on a server, you would not need the full path to the script, just a relative path.
Test the movie, and you should see a result similar to Figure 21.2.
Figure 21.2. The results of your first integration between Flash and ASP.
Wherever you see MYSERVER in the script, it is referring to the path to your server where the ASP pages reside.
That was a good example of connecting to an ASP page on a server and getting data back to Flash, but it is still not truly dynamic because we hard-coded the string to be sent back. The next example uses the built-in Now function in ASP to send back the date and time on the server.
When something is referred to as hard-coded, it means that the particular piece of code being referred to cannot be changed by outside forces, such as interaction with users or database information. It will stay exactly as the programmer coded it.
For this example, you need a new ASP page, so here is the code:
<%@Language=VBScript%> <%Option Explicit%> <% Response.Write("stamp=" & Now()) %>
Similar to the previous example, this example sends back a single name/value pair to Flash. This time, however, it uses the Now function to get the current time and date on the server. Also notice that an ampersand (&) is used to combine strings in VBScript. Save this script as geTDateStamp.asp and put it on your server. If you like, you can test the page to see what is being returned by simply mapping to it with a browser.
Now for the Flash part:
This code is very similar to the previous example, except we mixed it up a bit by setting the html property to true and the multiline property to true so it will display a little differently. Test it out and it should appear like Figure 21.3 but with a different date and time.
Figure 21.3. The first example of using ASP and Flash to create truly dynamic content.
It was not a lot of data, but it was dynamic, and you can tell because every time you test the Flash file, it will display different information.