Connecting Tech Pros Worldwide Forums | Help | Site Map

flash button not working in .net

Newbie
 
Join Date: Feb 2007
Posts: 25
#1: Oct 12 '07
i am using a flash template for my website.i am working on asp.net 2.0 for creating my website. this flash template has got buttons.on the click of the button i want the user to be redirected to the respective pages.hence i have written the following code in the action script window of flash for my "products" button
on (press)
{
getURL("products.aspx","_self","POST");
}
but when i run my page in asp.net the click of my products button does not show any change.it is still in the same page.what code should i write in order to make this button work?in short how do i redirect my flash button to the aspx page?Thanking in advance.

rrocket's Avatar
Member
 
Join Date: Aug 2007
Posts: 116
#2: Oct 25 '07

re: flash button not working in .net


Is it even possible to post variables to .NET? I have been searching the internet and only come up with info on how to do it with PHP. If anyone has any info on doing it with .NET (C#) I would appreciate it.
rrocket's Avatar
Member
 
Join Date: Aug 2007
Posts: 116
#3: Oct 26 '07

re: flash button not working in .net


I am trying to create a flash email form with Actionscript 3.0 and have gotten this far with it:
Expand|Select|Wrap|Line Numbers
  1. var variables:URLVariables = new URLVariables();
  2. var varSend:URLRequest = new URLRequest("http://thefreightrateco.com/dev/Contactus.aspx");
  3. var varLoader:URLLoader = new URLLoader;
  4. varSend.method = URLRequestMethod.POST;
  5. varSend.data = variables;
  6.  
  7. stop();
  8.  
  9. stage.focus = tbName;
  10.  
  11.  
  12. send_btn.addEventListener(MouseEvent.CLICK, sendEmail);
  13.  
  14. function sendEmail(event:MouseEvent):void
  15. {
  16.     variables.tbName = tbName.text;
  17.        variables.tbEmail = tbEmail.text;
  18.        variables.tbBody = tbBody.text;
  19.        varLoader.load(varSend);
  20. }
I have the same issue with the button not doing anything... I would prefer to use C# for the backend and am using .NET 2.0... Anyone have any ideas on what the problem is?
xNephilimx's Avatar
Expert
 
Join Date: Jun 2007
Location: Buenos Aires, Argentina
Posts: 200
#4: Oct 30 '07

re: flash button not working in .net


Hi! I really don't know anything about the .NET framework, I use php, but POST and GET are standard methods for sending variables to any server-side script.
Also if you are waiting any kind of response from the server when sending the request, it's just in vain, since you didn't added any event listener for the Complete event of the URLLoader object. Unless you add it and at least make the listener function trance something the flash movie won't do anything, but that doesn't mean it's not working.
You also missed the dataFormat for the URLLoader:

varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

If you want you can check this link http://livedocs.adobe.com/flex/201/h...ons_173_2.html
It's very helpfull, but it's for flex, anyway it's the same thing, just ommit the scope part (private, public and stuff)

Best regards
The_Nephilim

Quote:

Originally Posted by rrocket

I am trying to create a flash email form with Actionscript 3.0 and have gotten this far with it:

Expand|Select|Wrap|Line Numbers
  1. var variables:URLVariables = new URLVariables();
  2. var varSend:URLRequest = new URLRequest("http://thefreightrateco.com/dev/Contactus.aspx");
  3. var varLoader:URLLoader = new URLLoader;
  4. varSend.method = URLRequestMethod.POST;
  5. varSend.data = variables;
  6.  
  7. stop();
  8.  
  9. stage.focus = tbName;
  10.  
  11.  
  12. send_btn.addEventListener(MouseEvent.CLICK, sendEmail);
  13.  
  14. function sendEmail(event:MouseEvent):void
  15. {
  16.     variables.tbName = tbName.text;
  17.        variables.tbEmail = tbEmail.text;
  18.        variables.tbBody = tbBody.text;
  19.        varLoader.load(varSend);
  20. }
I have the same issue with the button not doing anything... I would prefer to use C# for the backend and am using .NET 2.0... Anyone have any ideas on what the problem is?

rrocket's Avatar
Member
 
Join Date: Aug 2007
Posts: 116
#5: Oct 30 '07

re: flash button not working in .net


Hello,

Thanks for the article... I did read it, but am still missing a few things.

This is what I have now:
Expand|Select|Wrap|Line Numbers
  1. var variables:URLVariables = new URLVariables();
  2. var varSend:URLRequest = new URLRequest();
  3. varSend.url = "http://www.thefreightrateco.com/dev/contactus.aspx";
  4. varSend.method = URLRequestMethod.POST;
  5. varSend.data = variables;
  6. var varLoader:URLLoader = new URLLoader();
  7. varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
  8. varLoader.addEventListener(Event.COMPLETE, sendEmail);
  9.  
  10.  
  11. stop();
  12.  
  13. stage.focus = tbName;
  14.  
  15.  
  16. send_btn.addEventListener(MouseEvent.CLICK, sendEmail);
  17.  
  18. function sendEmail(event:MouseEvent):void
  19. {
  20.     variables.tbName = tbName.text;
  21.        variables.tbEmail = tbEmail.text;
  22.        variables.tbBody = tbBody.text;
  23.        trace(varSend.data);
  24.     varLoader.load(varSend);
  25.     //varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
  26. }
The trace shows the right data and an error message:
Expand|Select|Wrap|Line Numbers
  1. tbEmail=Bob%40Bob%2Ecom&tbBody=Body%20of%20email&tbName=Bob
  2. Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
  3.     at Error$/throwError()
  4.     at flash.net::URLVariables/decode()
  5.     at flash.net::URLVariables$iinit()
  6.     at flash.net::URLLoader/flash.net:URLLoader::onComplete()
How do I append the query string to the URL?
xNephilimx's Avatar
Expert
 
Join Date: Jun 2007
Location: Buenos Aires, Argentina
Posts: 200
#6: Oct 30 '07

re: flash button not working in .net


I see, your problem is that your function sendEmail is only accepts mouse events.
Also, the event listener fot the URLLoader fires the function once the mail has already been sent. The mail is being sent when you click the button, the event listener for the URLLoader is just to keep track of the completition process.

So write a function to tell the user when the email has been sent.
and use the one you got (sendEmail) just for the mouse.

You cannot use a event handler function for various types of events.

You also need to pass the URL variables as a query string (like in Ajax), not by creating nonexistent properties.
Something like this: "param1=val1&param2=val2";

Your code would be like this now:

Expand|Select|Wrap|Line Numbers
  1. stop();
  2. var variables:URLVariables = new URLVariables();
  3. var varSend:URLRequest = new URLRequest("http://www.thefreightrateco.com/dev/contactus.aspx");
  4. varSend.method = URLRequestMethod.POST;
  5. var varLoader:URLLoader = new URLLoader();
  6. varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
  7. varLoader.addEventListener(Event.COMPLETE, onComplete);
  8.  
  9. stage.focus = tbName;
  10.  
  11.  
  12. send_btn.addEventListener(MouseEvent.CLICK, sendEmail);
  13.  
  14. function onCompete(e:Event):void {
  15.     trace('The email has been sent');
  16.     //you can add eny other functionality to actually tell the user
  17.     //I'm just tracing a legend
  18. }
  19.  
  20. function sendEmail(event:MouseEvent):void
  21. {
  22. variables.decode("tbName=" + tbName.text + "&tbEmail=") + tbEmail.text + "&tbBody=" + tbBody.text);
  23. varSend.data = variables;
  24.  
  25.        trace(varSend.data);
  26.  
  27.     varLoader.load(varSend);
  28. }
Try that and tell me how it worked

Best regards
The_Nephilim
rrocket's Avatar
Member
 
Join Date: Aug 2007
Posts: 116
#7: Oct 30 '07

re: flash button not working in .net


It is still giving me the same errors after I dropped the code you gave me in.

Thanks,
RRocket
Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#8: Nov 1 '07

re: flash button not working in .net


Quote:

Originally Posted by rrocket

Hello,

Thanks for the article... I did read it, but am still missing a few things.

This is what I have now:

Expand|Select|Wrap|Line Numbers
  1. var variables:URLVariables = new URLVariables();
  2. var varSend:URLRequest = new URLRequest();
  3. varSend.url = "http://www.thefreightrateco.com/dev/contactus.aspx";
  4. varSend.method = URLRequestMethod.POST;
  5. varSend.data = variables;
  6. var varLoader:URLLoader = new URLLoader();
  7. varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
  8. varLoader.addEventListener(Event.COMPLETE, sendEmail);
  9.  
  10.  
  11. stop();
  12.  
  13. stage.focus = tbName;
  14.  
  15.  
  16. send_btn.addEventListener(MouseEvent.CLICK, sendEmail);
  17.  
  18. function sendEmail(event:MouseEvent):void
  19. {
  20.     variables.tbName = tbName.text;
  21.        variables.tbEmail = tbEmail.text;
  22.        variables.tbBody = tbBody.text;
  23.        trace(varSend.data);
  24.     varLoader.load(varSend);
  25.     //varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
  26. }
The trace shows the right data and an error message:
Expand|Select|Wrap|Line Numbers
  1. tbEmail=Bob%40Bob%2Ecom&tbBody=Body%20of%20email&tbName=Bob
  2. Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
  3.     at Error$/throwError()
  4.     at flash.net::URLVariables/decode()
  5.     at flash.net::URLVariables$iinit()
  6.     at flash.net::URLLoader/flash.net:URLLoader::onComplete()
How do I append the query string to the URL?

Try this out:

Expand|Select|Wrap|Line Numbers
  1. function EmailPost(name, email, body)
  2. {
  3.     var postData = new LoadVars();
  4.  
  5.     //Load up all the variables you want to POST
  6.     postData.tbName = name;
  7.     postData.tbBody = body;
  8.     postData.tbEmail = email;
  9.  
  10.     postData.send("http://www.thefreightrateco.com/dev/contactus.aspx", "_self","POST");
  11. }
  12.  
xNephilimx's Avatar
Expert
 
Join Date: Jun 2007
Location: Buenos Aires, Argentina
Posts: 200
#9: Nov 1 '07

re: flash button not working in .net


Hi motoma, the functionalities of loadvars and others in AS2, in AS3 moved to the URLLoader Class, so LoadVars shouldn't work. at least in Flex2, I don't know if Flash CS3 offers some kind of backwards compatibility with AS2 when using AS3. Even thoug I don't think so, because you can choose which language you will use.

I'll try this exaple in flex to see if I made some typo in the way and post the working code.

Best regards,
The_Nephilim

Quote:

Originally Posted by Motoma

Try this out:

Expand|Select|Wrap|Line Numbers
  1. function EmailPost(name, email, body)
  2. {
  3.     var postData = new LoadVars();
  4.  
  5.     //Load up all the variables you want to POST
  6.     postData.tbName = name;
  7.     postData.tbBody = body;
  8.     postData.tbEmail = email;
  9.  
  10.     postData.send("http://www.thefreightrateco.com/dev/contactus.aspx", "_self","POST");
  11. }
  12.  

xNephilimx's Avatar
Expert
 
Join Date: Jun 2007
Location: Buenos Aires, Argentina
Posts: 200
#10: Nov 1 '07

re: flash button not working in .net


Got it, all you had to change was the dataFormat of the URLLoader to text.
I also reorganized the code into a function, so it's easier to read now:

Expand|Select|Wrap|Line Numbers
  1. send_btn.addEventListener(MouseEvent.CLICK, onClick);
  2.  
  3. function onClick(e:MouseEvent):void {
  4.     var src:String = "tbName=" + tbName.text + "&tbEmail=" + tbEmail.text + "&tbBody=" + tbBody.text;
  5.     var vars:URLVariables = new URLVariables(src);
  6.     var request:URLRequest = new URLRequest('http://www.thefreightrateco.com/dev/contactus.aspx');
  7.     request.method = URLRequestMethod.POST;
  8.     request.data = vars;
  9.  
  10.     var loader:URLLoader = new URLLoader();
  11.     loader.dataFormat = URLLoaderDataFormat.TEXT;
  12.  
  13.     loader.load(request);
  14. }
  15.  
I did this in Flex and it's working perfectly.

Best regards,
The_Nephilim
Reply