Link to home
Start Free TrialLog in
Avatar of codan87
codan87

asked on

Sending variables from as3 to asp.net and back

Hi there.

I have a flash movie sitting on an aspx page, and I want it to send variables from the movie to a different aspx page, and also read the variables coming back. The page it is communicating with is on the same domain.

When I play the movie in Adobe Flash CS3 it works perfectly.
When I play it on the final page, in a web browser (from server, not locally), the movie freezes between sending the data and receiving the new data.
When I try a third way, playing the movie from a locally stored simple html-page, it shows a warning right as it tries to make the connection. The movie also freezes when this warning is shown, so I assume this is why the movie freezes on the final page (though then no warning is shown).
Translated to english, the warning reads something like:

"Adobe Flash Player has stopped a potentially dangerous operation. The following file *filepath* is trying to communicate with this internetactivated location *domain*".

So my question of course how I make the movie work on the server.
I attach both the asp.net code and the as3 code.

About the flash movie.. I have to status textfields I use during debugging, called output and status. What this code is supposed to do is to send a variable from flash ("basilika"), and the aspx should return the variable tjosan, filled with #the_received_variable#.

AS3 code:
 
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.events.IOErrorEvent;
 
var myRequest:URLRequest;
var myVars:URLVariables;
var myLoader:URLLoader;
 
myVars = new URLVariables();
myRequest = new URLRequest();
myRequest.url='http://www.fragesporter.se/conny.aspx';
myRequest.method=URLRequestMethod.POST;
myRequest.data=myVars;
 
myLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.TEXT;
myLoader.addEventListener(Event.COMPLETE, completeHandler);
myLoader.addEventListener(IOErrorEvent.IO_ERROR, showError);
 
function completeHandler(event:Event):void {
	var newVars:URLVariables = new URLVariables(event.target.data);
 
	status.text = "waiting over!";
	output.text = newVars.tjosan;
 
}
function showError(e:IOErrorEvent) {
	trace("There was an error!");
}
 
nextButton.addEventListener(MouseEvent.CLICK, gotoGo);
function gotoGo(event:MouseEvent):void {
	status.text = "vänta...";
	requestVerification();
}
 
 
function requestVerification():void {
 
	output.text = "requesting";
 
	myVars.mode = "basilika";
	myRequest.url = myRequest.url + "?mode=" + myVars.mode;
	myLoader.load(myRequest);// this sends the variables and loads new data from Conny.aspx
 
}
 
 
 
ASP.NET code in Conny.aspx:
    protected void Page_Load(object sender, EventArgs e)
    {   
        String moj = Request.QueryString["mode"];
        Response.Write("tjosan="#"+moj+"#");
    }
 
 
The movie is integrated into a aspx-page with this code:
	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="600" height="300" id="mainQuiz" align="middle">
	<param name="allowScriptAccess" value="sameDomain" />
	<param name="allowFullScreen" value="false" />
	<param name="movie" value="mainQuiz.swf" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="mainQuiz.swf" loop="false" menu="false" quality="high" bgcolor="#ffffff" width="600" height="300" name="mainQuiz" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
	</object>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of amx
amx
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of codan87
codan87

ASKER

Thank you! Using a relative path fixed the problem. Your tip on how to handle the data also decluttered my code a bit.
I would add to amx's comment above that you should also comment out any code that would attempt to run the video and comment out the eventListener for the "complete" event and the "Requesting" event.  

After commenting everything but the click handler out in flash, then put the following after your 'request["mode"]':

          response.write(moj)
          response.end
I apologize as there is no "Requesting" event.  Ignore that part of my above post.