all groups > flash (macromedia) > december 2003 >
You're in the

flash (macromedia)

group:

can flash use session variables?


can flash use session variables? artane
12/28/2003 10:33:17 PM
flash (macromedia): hey guys,

I've created an html/asp web page with a standard form that asks the user to enter their "username". When the user does this and clicks submit, he is taken to another html page that contains a flash movie. I want this flash movie to display the "username" entered on the previous page.

I figure, I can make the username a session variable and then have the flash movie reference it. Is this possible? What would the actionscript look like?

Thank-you very much!

artane


Re: can flash use session variables? richuno
12/28/2003 11:56:04 PM
Since you are using ASP, it is quite simple. I use ASP VBScript .

First create an asp page that is nothing more than a call to your session variable. Then write the variable as a text string.


<%
myVariable = Session("username")
%>
<%= "myVariable="&myVariable %>


Your Flash movie will simply load the variable 'myVariable' by using loadVariables...

loadVariables("http://yourasppage.asp", _root, "POST");

your movie will use the variable name you specify in the asp page as the dyn. text variable in the movie.

If your movie has trouble loading the variable (which is a problem I experience from time to time) try defining the variable in your embed tags for your movie.

- Hope this helps

Re: can flash use session variables? Laiverd.COM
12/29/2003 12:09:05 AM
Have a look at the local shared object. Allows you to store and retrieve
data local.

John

--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

Re: can flash use session variables? artane
12/29/2003 12:31:40 AM
Hi Richuno!

Thanks so much for your reply, I am using ASP VBScript too! It's so nice to hear that this is possible!

So, I see how I would create the variable with ASP but, I'm unsure of how I would call it from Flash in my particular case. Blow is the actionscript I'm working with (very simple). Right now, it displays "test" as the username. I want it to display the username that's in the session variable.

......................................................................................................................................

username="test";

client_nc=new NetConnection();
client_nc.connect("rtmp://app420al.rtmphost.com/noConnect", username);

avpresence_mc.connect(client_nc);
avpresence_mc.setUsername(username);

....................................................................................................................................

I think all I would have to do is replace "test" with the path (or name) to the session variable. I'm unsure, am I right? How exactly should my script look?

Thank-you very much Richuno, this has been bugging me for 2 weeks. If you help me make this work you're a life saver!

artane



Re: can flash use session variables? richuno
12/29/2003 12:48:25 AM
I've always used loadVariables, but I think it is being phased out. I've never even used the netConnection() function. I'll play around with it a bit and see what I can figure out. In the meantime.. just comment out the netConnection routine and replace it with the loadVariables. Maybe not as clean, but I think it will do what you want.

Re: can flash use session variables? artane
12/29/2003 4:21:17 AM
hey richuno,

Sorry, I should have mentioned that this script is for flash communication server. The netConnection stuff doesn't have to change, it is simply the first line of script that concerns me:

username="test";


I need to replace "test" with the "username" found in a session variable I'll create with ASP. Basically, a user logs in (via an ASP form) and that username is stored in a session variable. Then, when they navigate to the page that contains the flash movie in question, the movie loads and displays the user's "username" in the movie. It does this via the above line of code. Something like...

username="the session variable";


So, it is not a text field on the stage I need to be dynamic, it is text within the Actionscript. I think loadVariables is the key but, I don't know where to begin, I really don't know much about Actionscript. How would you go about doing it? Can you think of a way to load the ASP variable and use it in this line of script?

Thank you Richuno, you're my only hope.

artane




Re: can flash use session variables? richuno
12/29/2003 7:45:18 PM
OK, that explains why I've never used the netConnection. I don't use the communication server. I do, however use Flash movies and games that utilize dynamic database driven content. For an example you can visit a dev. stage site that I have written a poker game for. The game logs you in based on the submitted user/password information. It pulls your saved score into the movie and updates your score in the database with each hand lost or won. While not exactly what you are looking for, it does offer a way to acheive your desired results, I think.

ispfriends.com is the domain if you would like to see the movie in action.

The way I communicate with the database is through a series of asp pages. These are script pages that are not displayed in the visitors browser. They are called from within the Flash movie by using the loadVariables function.

It can get tricky though, if your data needs to be pulled into a nested clip.

IE, if you have a routine running that is an instance named ' username' the call would look like

loadVariables("http://script.asp", _root.username, "POST");

I have had movies get even more particular, and I don't know the reason, but they require that same code to be written...

loadVariables("http://script.asp", _level0.username, "POST");

Below is the actual code from the game that makes an update to the database...

score = ( Number(score) + Addscore() );
points = score;
loadVariables("script.asp", _root.pokerX, "POST");
if(score == 0){
score = 100;
winner = "100 points added"


and this is the script.asp page that the movie is calling... (I am using a flatfile for point scoring, but DB connections work equally well)

<%@LANGUAGE="VBSCRIPT"%>
<%
WriteText=(Request.Form("points"))
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f, Msg
Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.OpenTextFile("F:\*******\cgi-bin\gameUsers\"&(Session("thisUsername"))&".txt", ForWriting, True)
f.Write WriteText
%>
<%="points="&WriteText %>

The Flash movie passes the new score as a form value "points" then writes the points value to the page, the movie then picks up the points value string that '<%="points="&WriteText %>' writes and the movie updates the players points in the game.

Oh, and it is my old friend tellTarget, not loadVariables that is being depreciated. So no worries about having to recode the whole thing for the next version out.

I hope this is helpful. - Rich

Developing interactive Flash and ASP pages for 'Real World' application.

Referring URLs
www.ispfriends.com/games.asp



Re: can flash use session variables? richuno
12/29/2003 7:56:50 PM
You know, I've been looking at this from a programming slant, not a Flash movie perspective....

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="600" height="400">
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ IMPORTANT CODE SNIP BELOW
<param name=movie value="movie.swf?username=<%=Session("Username")%>">
<param name=quality value=high>
<param name="SCALE" value="noborder">
<param name="LOOP" value="false">
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ IMPORTANT CODE SNIP BELOW
<embed src="movie.swf?username=<%=Session("Username")%>" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="600" height="250" scale="noborder" loop="false" name="slots">
</embed>
</object>

That will do the job, if the username does not change...

Re: can flash use session variables? artane
12/30/2003 6:02:35 AM
Thanks alot Rich!

That's alot of material I can meditate on for the next little while :) I'll figure this out, it's just a matter of time.

artane

Re: can flash use session variables? 802
3/12/2004 11:17:48 AM
Hi!

I'm trying to learn flash and got interested when I saw this piece of code:
<param name=movie value="movie.swf?username=<%=Session("Username")%>">

Does this mean that an instance of the "movie.swf" is created on the server
and is executed in its own secure process or a shared process? Could you also
give me an example of code that collects these values within the flash movie?
Is it the loadVariables-method maybe???

Thanks
/s




AddThis Social Bookmark Button