A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: simple? asp load variables

  1. #1
    Senior Member
    Join Date
    Sep 2000
    Location
    New Zealand
    Posts
    271

    simple? asp load variables

    Greetings

    I'm trying to load some variables from an asp page.

    The asp page looks like this:
    PHP Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--
    #include file="../Connections/cnnNewFreeway.asp" -->
    <%
    Dim rsTest__MMColParam
    rsTest__MMColParam 
    "49"
    If (Request("MM_EmptyValue") <> ""Then 
      rsTest__MMColParam 
    Request("MM_EmptyValue")
    End If
    %>
    <%
    Dim rsTest
    Dim rsTest_numRows

    Set rsTest 
    Server.CreateObject("ADODB.Recordset")
    rsTest.ActiveConnection MM_cnnNewFreeway_STRING
    rsTest
    .Source "SELECT ContentID, Title, ShortDesc FROM dbo.Content WHERE ContentID = " Replace(rsTest__MMColParam"'""''") + ""
    rsTest.CursorType 0
    rsTest
    .CursorLocation 2
    rsTest
    .LockType 1
    rsTest
    .Open()

    rsTest_numRows 0
    %>
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </
    head>

    <
    body>
    <
    p><%=(rsTest.Fields.Item("Title").Value)%> </p>
    <
    p><%=(rsTest.Fields.Item("ShortDesc").Value)%> </p>
    </
    body>
    </
    html>
    <%
    rsTest.Close()
    Set rsTest Nothing
    %> 
    And my flash movie, which has a dynamic text box on the root, with a of 'ShortDesc'

    Heres the ActionScript i'm using:
    loadVariablesNum("http://groundzero/freeway/test_asp.asp", 0, "GET");


    But nothing is working, can anyone identify what I'm doing wrong?

  2. #2
    Member
    Join Date
    Aug 2001
    Location
    Hawaii
    Posts
    64
    To send variables to flash from the asp file, you need a 'Response.Write' statement.


    <%
    Dim test1
    test1=400
    Response.Write ("&varTest=" & test1)
    %>


    This will send the variable 'varTest' with a value of 400. Note that Flash might treat 400 as a string, not a number.
    Always make sure that when you load variables, they are actually loaded before using them. Basically this means you can't use them
    in the same keyframe where the loadvariables action is executed. You will have to perform some kind of loop that checks if varTest
    excists.
    This is a check, put in keyframe 3 of the main timeline. The first keyframe has a loadvariablesnum() action. The second keyframe is
    blank.


    if (varTest != null) {
    //loaded - have some action here
    trace(varTest)
    } else {
    not loaded - go back and check again
    gotoAndPlay (2);
    }


    Note that a comparisson in an if() statement needs two equal signs '==' not one.
    if (test1==400)

    In this case:
    if (number(varTest)==400)

    Hope this helps.

    light4u
    Last edited by light4u; 03-25-2003 at 11:35 AM.
    Design & Marketing
    http://www.dreamteammedia.com

  3. #3
    Senior Member
    Join Date
    Sep 2000
    Location
    New Zealand
    Posts
    271
    Hi light4u

    thanks for the reply

    Tried your suggestion and it outputs 400 - so all ok there.

    And I've changed my asp code to use response.write and the page is working fine, but its still not showing up in Flash.

    So i guess the problem is with my flash code.

    On the first frame I have
    loadVariablesNum("http://groundzero/freeway/test_asp.asp", 0, "GET");


    and I have a dynamic text box with the variable of Title

    any ideas what I might be doing wrong?

  4. #4
    Member
    Join Date
    Aug 2001
    Location
    Hawaii
    Posts
    64
    Zip up your ASP code, databae and your .fla and mail it to me.
    I will have a look and see what the problem is.
    Last edited by light4u; 03-26-2003 at 12:03 PM.
    Design & Marketing
    http://www.dreamteammedia.com

  5. #5
    Member
    Join Date
    Aug 2001
    Location
    Hawaii
    Posts
    64
    Ok I have put a sample together.
    FYI:
    Most of the asp stuff I have learned has been from various websites and poeple on Flashkik.This example has been modified from http://www.zymotik.com.
    Database: intranet.mdb
    ASP Page 1: loadvalues.asp
    ASP Page 2: config.asp
    HTML: loadvariables.html
    Flash: loadvariables.swf
    My database is named intranet My table is named contentand looks like this:

    Here is what my ASP code looks like. Although it is not nessacerry to use two ASP pages to call the variables from the database I am just using this an example to give you a better idea of what you can do.
    ASP Page 1: config.asp

    <%
    ' Things you can change:
    ' Just edit the variable values in this script...

    ' Name and path of your dabase (eg: "intranet.mdb")

    databasefile = "data/intranet.mdb"

    ' Database username? You can leave it as just "" if blank. (eg: "" or "admin")

    dbusername = ""

    ' Database Password? You can leave it as just "" if blank. (eg: "" or "password")
    '
    dbpassword = ""
    '
    ' If you want to be emailed when someone makes an entry,
    ' insert your email address below. If you don't, leave it as ""
    ' (e.g: "till@itouchmedia.com" or "")

    useremail = "youknowwho@youknwwho.com"

    cst = "Provider=Microsoft.Jet.OLEDB.4.0;"
    cst = cst & "Data Source="&server.mappath(databasefile)&";User Id="&dbusername&";Password="&dbpassword&";"
    set conn = server.createobject("adodb.connection")
    conn.open cst
    %>

    ASP Page 2: loadvalues.asp


    <%@LANGUAGE="VBSCRIPT"%><!--#include file="config.asp" --><%
    set content = Server.CreateObject("ADODB.Recordset")
    'content.ActiveConnection = MM_contentdata_STRING
    'content.Source = "SELECT ID, ShortDesc, Title, date FROM content ORDER BY date DESC"
    content.CursorType = 0
    content.CursorLocation = 2
    content.LockType = 3
    content.open "SELECT ID, ShortDesc, Title, date FROM content ORDER BY date DESC", conn
    content_numRows = 0
    %>
    <%
    ' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

    ' set the record count
    content_total = content.RecordCount

    ' set the number of rows displayed on this page
    If (content_numRows < 0) Then
    content_numRows = content_total
    Elseif (content_numRows = 0) Then
    content_numRows = 1
    End If

    ' set the first and last displayed record
    content_first = 1
    content_last = content_first + content_numRows - 1

    ' if we have the correct record count, check the other stats
    If (content_total <> -1) Then
    If (content_first > content_total) Then content_first = content_total
    If (content_last > content_total) Then content_last = content_total
    If (content_numRows > content_total) Then content_numRows = content_total
    End If
    %>
    <%
    ' *** Recordset Stats: if we don't know the record count, manually count them

    If (content_total = -1) Then

    ' count the total records by iterating through the recordset
    content_total=0
    While (Not content.EOF)
    content_total = content_total + 1
    content.MoveNext
    Wend

    ' reset the cursor to the beginning
    If (content.CursorType > 0) Then
    content.MoveFirst
    Else
    content.Requery
    End If

    ' set the number of rows displayed on this page
    If (content_numRows < 0 Or content_numRows > content_total) Then
    content_numRows = content_total
    End If

    ' set the first and last displayed record
    content_first = 1
    content_last = content_first + content_numRows - 1
    If (content_first > content_total) Then content_first = content_total
    If (content_last > content_total) Then content_last = content_total

    End If
    %>

    <%
    ' *** Move To Record and Go To Record: declare variables

    Set MM_rs = content
    MM_rsCount = content_total
    MM_size = content_numRows
    MM_uniqueCol = ""
    MM_paramName = ""
    MM_offset = 0
    MM_atTotal = false
    MM_paramIsDefined = false
    If (MM_paramName <> "") Then
    MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
    End If
    %>
    <%
    ' *** Move To Record: handle 'index' or 'offset' parameter

    if (Not MM_paramIsDefined And MM_rsCount <> 0) then

    ' use index parameter if defined, otherwise use offset parameter
    r = Request.QueryString("index")
    If r = "" Then r = Request.QueryString("offset")
    If r <> "" Then MM_offset = Int(r)

    ' if we have a record count, check if we are past the end of the recordset
    If (MM_rsCount <> -1) Then
    If (MM_offset >= MM_rsCount Or MM_offset = -1) Then ' past end or move last
    If ((MM_rsCount Mod MM_size) > 0) Then ' last page not a full repeat region
    MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
    Else
    MM_offset = MM_rsCount - MM_size
    End If
    End If
    End If

    ' move the cursor to the selected record
    i = 0
    While ((Not MM_rs.EOF) And (i < MM_offset Or MM_offset = -1))
    MM_rs.MoveNext
    i = i + 1
    Wend
    If (MM_rs.EOF) Then MM_offset = i ' set MM_offset to the last possible record

    End If
    %>
    <%
    ' *** Move To Record: if we dont know the record count, check the display range

    If (MM_rsCount = -1) Then

    ' walk to the end of the display range for this page
    i = MM_offset
    While (Not MM_rs.EOF And (MM_size < 0 Or i < MM_offset + MM_size))
    MM_rs.MoveNext
    i = i + 1
    Wend

    ' if we walked off the end of the recordset, set MM_rsCount and MM_size
    If (MM_rs.EOF) Then
    MM_rsCount = i
    If (MM_size < 0 Or MM_size > MM_rsCount) Then MM_size = MM_rsCount
    End If

    ' if we walked off the end, set the offset based on page size
    If (MM_rs.EOF And Not MM_paramIsDefined) Then
    If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then
    If ((MM_rsCount Mod MM_size) > 0) Then
    MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
    Else
    MM_offset = MM_rsCount - MM_size
    End If
    End If
    End If

    ' reset the cursor to the beginning
    If (MM_rs.CursorType > 0) Then
    MM_rs.MoveFirst
    Else
    MM_rs.Requery
    End If

    ' move the cursor to the selected record
    i = 0
    While (Not MM_rs.EOF And i < MM_offset)
    MM_rs.MoveNext
    i = i + 1
    Wend
    End If
    %>
    <%
    ' *** Move To Record: update recordset stats

    ' set the first and last displayed record
    content_first = MM_offset + 1
    content_last = MM_offset + MM_size
    If (MM_rsCount <> -1) Then
    If (content_first > MM_rsCount) Then content_first = MM_rsCount
    If (content_last > MM_rsCount) Then content_last = MM_rsCount
    End If

    ' set the boolean used by hide region to check if we are on the last record
    MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
    %>
    <%
    ' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

    ' create the list of parameters which should not be maintained
    MM_removeList = "&index="
    If (MM_paramName <> "") Then MM_removeList = MM_removeList & "&" & MM_paramName & "="
    MM_keepURL="":MM_keepForm="":MM_keepBoth="":MM_kee pNone=""

    ' add the URL parameters to the MM_keepURL string
    For Each Item In Request.QueryString
    NextItem = "&" & Item & "="
    If (InStr(1,MM_removeList,NextItem,1) = 0) Then
    MM_keepURL = MM_keepURL & NextItem & Server.URLencode(Request.QueryString(Item))
    End If
    Next

    ' add the Form variables to the MM_keepForm string
    For Each Item In Request.Form
    NextItem = "&" & Item & "="
    If (InStr(1,MM_removeList,NextItem,1) = 0) Then
    MM_keepForm = MM_keepForm & NextItem & Server.URLencode(Request.Form(Item))
    End If
    Next

    ' create the Form + URL string and remove the intial '&' from each of the strings
    MM_keepBoth = MM_keepURL & MM_keepForm
    if (MM_keepBoth <> "") Then MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
    if (MM_keepURL <> "") Then MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
    if (MM_keepForm <> "") Then MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)

    ' a utility function used for adding additional parameters to these strings
    Function MM_joinChar(firstItem)
    If (firstItem <> "") Then
    MM_joinChar = "&"
    Else
    MM_joinChar = ""
    End If
    End Function
    %>
    <%
    ' *** Move To Record: set the strings for the first, last, next, and previous links

    MM_keepMove = MM_keepBoth
    MM_moveParam = "index"

    ' if the page has a repeated region, remove 'offset' from the maintained parameters
    If (MM_size > 0) Then
    MM_moveParam = "offset"
    If (MM_keepMove <> "") Then
    params = Split(MM_keepMove, "&")
    MM_keepMove = ""
    For i = 0 To UBound(params)
    nextItem = Left(params(i), InStr(params(i),"=") - 1)
    If (StrComp(nextItem,MM_moveParam,1) <> 0) Then
    MM_keepMove = MM_keepMove & "&" & params(i)
    End If
    Next
    If (MM_keepMove <> "") Then
    MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)
    End If
    End If
    End If

    ' set the strings for the move to links
    If (MM_keepMove <> "") Then MM_keepMove = MM_keepMove & "&"
    urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="
    MM_moveFirst = urlStr & "0"
    MM_moveLast = urlStr & "-1"
    MM_moveNext = urlStr & Cstr(MM_offset + MM_size)
    prev = MM_offset - MM_size
    If (prev < 0) Then prev = 0
    MM_movePrev = urlStr & Cstr(prev)
    %>
    &atitle=<%=Server.URLEncode(content.Fields.Item("T itle").Value)%>&ashortdesc=<%=Server.URLEncode(con tent.Fields.Item("ShortDesc").Value)%>&adate=<%=Se rver.URLEncode(content.Fields.Item("date").Value)% >&ip=<%=Request.ServerVariables("REMOTE_ADDR")%>&s ervername=<%=Request.ServerVariables("REMOTE_HOST" )%>&remoteuser=<%Request.ServerVariables("REMOTE_U SER")%>&totalcount=<%=(content_total)%>&offset=<%= MM_offset + 1%><%
    content.Close()
    set content = Nothing
    conn.Close()
    Set conn = Nothing
    %>

    SEE FINISHED SAMPLE HERE

    There you have it!
    light4u
    Design & Marketing
    http://www.dreamteammedia.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center