[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6672
  • Last Modified:

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

0
codan87
Asked:
codan87
  • 2
  • 2
2 Solutions
 
amxCommented:
Have you tried making the path in your actionscript relative?

eg.
myRequest.url='conny.aspx';

I'm assuming the flash file and aspx pages are all in the same directory
0
 
amxCommented:
I just noticed that your posting the data from flash but the aspx is expecting it as part of a querystring.

You can either change the flash file to send the data as a querystring or changes the aspx page to get you data like this:

 String moj = Request["mode"]
0
 
codan87Author Commented:
Thank you! Using a relative path fixed the problem. Your tip on how to handle the data also decluttered my code a bit.
0
 
Unzip_The_RipperCommented:
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
0
 
Unzip_The_RipperCommented:
I apologize as there is no "Requesting" event.  Ignore that part of my above post.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now