Solved

Importing .ASP output data into Flash

Posted on 2008-10-09
3
579 Views
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
eg.http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/Q_20683998.html?sfQueryTermInfo=1+asp+flash


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

      <%@ Language=VBScript %>
      <% Option Explicit %>
      <%
      Response.Write("5,11,12,13,14,15")
      %>

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

      loader.load(request);

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();
      loader.load(request);

      trace(request.data);

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)
http://www.nsia.ca/P1/home.asp

thx



0
Comment
Question by:GeorgeJacobson
  • 2
3 Comments
 
LVL 18

Assisted Solution

by:Antonio Estrada
Antonio Estrada earned 125 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:

<code>

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.

-V
<%

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.

</div>
 

<script type="text/javascript">

   var so = new SWFObject("myMovie.swf", "myMovie", "550", "400", "8", "#ffffff");

   so.addParam("wmode","transparent");

   so.addVariable("someString","<%=myASPVar%>");

   so.write("flashcontent");

</script>

Open in new window

0
 

Author Comment

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

Accepted Solution

by:
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>
</object>




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);
addChild(myUILoader);
var arrIds:Array;
var nIds:int = 1;
var curId:int = 1;

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

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);
      minuteTimer.start();
}

function onTick(event:TimerEvent):void
{
      if( curId == nIds )
            curId = 1;
      else
            curId++;
      
      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=64.225.112.40;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")
      rsLogosIds.movenext
      nlogos = nlogos + 1
Loop
rsLogosIds.Close()
Set rsLogosIds = nothing
sLogosIds = nLogos & sLogosIds

response.Write(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=64.225.112.40;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
      rs.Close
      Set rs = Nothing
      cn.Close()
      Set cn = nothing
End if
%>

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

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now