Importing .ASP output data into Flash

Posted on 2008-10-09
Medium Priority
Last Modified: 2013-11-11
Importing .ASP output data into Flash
I am having trouble with ActionScript 3.0 to read or import data from .ASP page into Flash.
This questionj is about .ASP and Flash interconnnectivity.
I am new to ActionScript 3.0, and have studied Flash for 2 days.
Note I have tried the EE knowledgebase

First, suppose the congtent of file test.asp contains as follows:

      <%@ Language=VBScript %>
      <% Option Explicit %>

Then my objective is to read the output from that particular .asp (test.asp), and to put them
into ActionScript 3.0 internal array "someArray", which has this declaration:

      var someArray:Array  // literal value

After this reading in, the content of array "someArray" is [5 11 12 13 14 15].
Alternatively, it can also be put in string "someString", whose declaration is:

      var someArray:String  // literal value

After this reading in, the content of array "someArray" is "5,11,12,13,14,15".

Reason why I'm doing this is it when it comes to obtaining data from SQL server.
In that case, from a particular database Table that contains 6 records whose particular field value are
5,11,12,13,14, and 15. This is done with .ASP's Recordset, and it produces output "5,11,12,13,14,15"
using Response.Write(rs("someField")) in a loop for all 6 records.
Note that using SQL server is responsibility of .ASP - That part I already know and is working well.

I seem to have no success in ActionScripting.
I tried URLRequest, URLLoader, URLVariables, URLStream, etc...
I called


in ActionScrip to load data into "myRequest" and I get nothing or errors!

Code I used is:
      var request:URLRequest = new URLRequest("test.asp");
      var loader:URLLoader = new URLLoader();


This gives me error at "Trace()" call because "request.data" is NULL.
This also occurs even when I use Imports as follows:

      import flash.net.URLRequest;
      import flash.net.URLLoader;
Update 10.10.08
The objective of integrating Flash to SQLServer is to replace the image scroller at the top of this page (which uses JavaScript).  Of note, the image scroller at the bottom of the page uses Flash (with images hard-coded)


Question by:GeorgeJacobson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 18

Assisted Solution

by:Antonio Estrada
Antonio Estrada earned 500 total points
ID: 22703773
Truth is, you don't need any of those classes to get that kind of communication with Flash.

The idea to do this is the following:

ASP (SQL) --> HTML/JavaScript --> Flash

So how to do it? First than anything, please get swfobject from this place: http://blog.deconcept.com/swfobject/

Here's how your code would look like after implementing swfObject:


Now you have the variable someString on Flash and can play with it around. Some advice though: create the variable someString in your Flash project while you're developing it, after you're done delete it so it takes the values from the ASP page.

Option Explicit
Dim myASPVar
myASPVar = "5,11,12,13,14,15"
<script type="text/javascript" src="swfobject.js"></script>
<div id="flashcontent">
  This text is replaced by the Flash movie.
<script type="text/javascript">
   var so = new SWFObject("myMovie.swf", "myMovie", "550", "400", "8", "#ffffff");

Open in new window


Author Comment

ID: 22725294
Thank you.  I am working on an alternate solution and will update as soon as it is done.  

Accepted Solution

GeorgeJacobson earned 0 total points
ID: 22735357
This is the solution we successfully developed over here:
NOTES about ActionScript for NSIA Logos Flash Object

1.  Needed 'import' statements for TimerEvent, Timer, Event, and UILoader

2.  Declare variables URLRequest, URLLoader, URLVariables, UILoader, and Timer with 'new' instants.

3.  Variables 'arrIds' for array of image Id's, 'nIds' for number of images, and 'curId' for current image Id - declared in main routine.

4.  Must need addChild(myUILoader) to enable the displaying of these Logo images.

5.  Array arrIds content must be obtained inside onLoaded(evt:Event):void function call; otherwise, this array won't get any data.
    Use Trace(myLoader.data) statement to display the contents of read-in input data inside 'onLoaded(event)' function.
    This function contains assignment of 1st image's URL as well as establishing a timer system via variable 'minuteTimer'.

6.  function onTick(event:TimerEvent):void is used for changing onto next image every 1 second by re-assigning 'myUILoader.source' a new URL.

7.  function completeHandler(event:Event):void is used for re-sizing each Logo image to fit in 240 by 120 display area,
    done by having Event-Listener for UILoader, called with function addEventListener(Event.COMPLETE, completeHandler) in main routine.

Flash object is called 'Logos.swf'.

In HTML file, this object is called with this HTML construct:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="261" height="125" ID="Shockwaveflash1" VIEWASTEXT>
      <param name="movie" value="logos.swf" />
      <param name="quality" value="high" />
      <embed src="logos.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="261" height="125"></embed>

Source ActionScript 3.0 codes:

import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.events.Event;
import flash.net.*;
import fl.containers.UILoader;

var myRequest:URLRequest = new URLRequest("LogoImageIds.asp");
var myLoader:URLLoader = new URLLoader();
var myVariables:URLVariables = new URLVariables();
var myUILoader:UILoader = new UILoader();
myUILoader.addEventListener(Event.COMPLETE, completeHandler);
var arrIds:Array;
var nIds:int = 1;
var curId:int = 1;

myRequest.method = URLRequestMethod.GET;
myRequest.data = myVariables;
myLoader.addEventListener(Event.COMPLETE, onLoaded);

function onLoaded(evt:Event):void {
      arrIds = myLoader.data.split(", ");
      nIds = arrIds[0];
      curId = 1 + Math.floor(nIds*Math.random());
      myUILoader.source = "dbnsiaImage.asp?Id="+arrIds[curId];
      var minuteTimer:Timer = new Timer(1000);
       minuteTimer.addEventListener(TimerEvent.TIMER, onTick);

function onTick(event:TimerEvent):void
      if( curId == nIds )
            curId = 1;
      myUILoader.source = "dbnsiaImage.asp?Id="+arrIds[curId];

function completeHandler(event:Event):void {
    var uiLdr:UILoader = event.currentTarget as UILoader;
    var image:DisplayObject = uiLdr.content as DisplayObject;
    uiLdr.setSize(240,120);      ///uiLdr.setSize(image.width, image.height);
    uiLdr.move((stage.stageWidth - 240) / 2, (stage.stageHeight - 120) / 2);

This ActionScript is accessable by pressing keyboard key 'F9' (or with menu 'Window' --> 'Actions').
Yet the source code for 'Logos.swf' is 'Logos.fla', and this can be totally empty with one Frame and one Layer
but its property must be set to have 20 or more frames per seconds, and dimension of this stage is set to be 240 px by 120 px.

Source code of LogoImageIds.asp:

<%@ Language=VBScript %>
<% Option Explicit
   Response.Expires = -1442

Dim nlogos, ilogo 'As Integer
Dim sLogosIds 'As String
Dim rsLogosIds 'As ADODB.Recordset

function rdRecordset(sql) 'As ADODB.Recordset
      ''This function returns a read only,forward only recordset
      Dim rs 'As ADODB.Recordset
      Set rs = Server.CreateObject("ADODB.Recordset")
      with rs
            .LockType = 1 ''adLockReadOnly ''Defined in adovbs.inc
            .CursorLocation = 2 ''adUseServer
            .CursorType = 0 ''adOpenForwardOnly
            .open sql, "Provider=SQLOLEDB.1;Server=;Persist Security Info=False;User ID=******;Password=******;Initial Catalog=dbnsia;Network Library=dbmssocn"
      end with
      Set rdRecordset = rs
end function

nlogos = 0
sLogosIds = ""
Set rsLogosIds = rdRecordset("SELECT UserImageId FROM UserImages INNER JOIN Users ON UserImages.UserId = Users.UserId WHERE Verified = '1' AND Sponsors = '1' AND  UserActive = '1'")
Do while not rsLogosIds.EOF
      sLogosIds = sLogosIds & ", " & rsLogosIds("UserImageId")
      nlogos = nlogos + 1
Set rsLogosIds = nothing
sLogosIds = nLogos & sLogosIds


Source code of dbnsiaImage.asp:
<%@ Language=VBScript %>
<% Option Explicit

Dim cn 'AS ADODB.Connection
Dim rs 'AS ADODB.Recordset
Dim Id 'AS String

Response.Buffer = true
Id = Request.QueryString("Id")
If Request.QueryString.Item = "Id="&Id AND Id>"0" AND IsNumeric(Id) AND InStr(Id," ")=0 AND InStr(Id,".")=0 AND InStr(Id,"-")=0 Then
      Set cn = server.CreateObject("ADODB.Connection")
      cn.Open      "Provider=SQLOLEDB.1;Server=;Persist Security Info=False;User ID=******;Password=******;Initial Catalog=dbnsia;Network Library=dbmssocn"
      set rs = Server.CreateObject("ADODB.Recordset")
      rs.Open "GetAnUserImage "&Id, cn
      If not rs.EOF Then
            Response.ContentType = rs("ImageType")
            Response.BinaryWrite rs("ImageContent")
      End if
      Set rs = Nothing
      Set cn = nothing
End if

NOTE: Images from this database can be of type .gif, .jpg, or .png, but cannot be of type .bmp.


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question