flash button not working in .net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anuparvathy
    New Member
    • Feb 2007
    • 25

    flash button not working in .net

    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("product s.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
    New Member
    • Aug 2007
    • 116

    #2
    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.

    Comment

    • rrocket
      New Member
      • Aug 2007
      • 116

      #3
      I am trying to create a flash email form with Actionscript 3.0 and have gotten this far with it:
      [code=actionscri pt]var variables:URLVa riables = new URLVariables();
      var varSend:URLRequ est = new URLRequest("htt p://thefreightratec o.com/dev/Contactus.aspx" );
      var varLoader:URLLo ader = new URLLoader;
      varSend.method = URLRequestMetho d.POST;
      varSend.data = variables;

      stop();

      stage.focus = tbName;


      send_btn.addEve ntListener(Mous eEvent.CLICK, sendEmail);

      function sendEmail(event :MouseEvent):vo id
      {
      variables.tbNam e = tbName.text;
      variables.tbEma il = tbEmail.text;
      variables.tbBod y = tbBody.text;
      varLoader.load( varSend);
      }[/code]

      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?

      Comment

      • xNephilimx
        Recognized Expert New Member
        • Jun 2007
        • 213

        #4
        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.dataF ormat = URLLoaderDataFo rmat.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

        Originally posted by rrocket
        I am trying to create a flash email form with Actionscript 3.0 and have gotten this far with it:
        [code=actionscri pt]var variables:URLVa riables = new URLVariables();
        var varSend:URLRequ est = new URLRequest("htt p://thefreightratec o.com/dev/Contactus.aspx" );
        var varLoader:URLLo ader = new URLLoader;
        varSend.method = URLRequestMetho d.POST;
        varSend.data = variables;

        stop();

        stage.focus = tbName;


        send_btn.addEve ntListener(Mous eEvent.CLICK, sendEmail);

        function sendEmail(event :MouseEvent):vo id
        {
        variables.tbNam e = tbName.text;
        variables.tbEma il = tbEmail.text;
        variables.tbBod y = tbBody.text;
        varLoader.load( varSend);
        }[/code]

        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?

        Comment

        • rrocket
          New Member
          • Aug 2007
          • 116

          #5
          Hello,

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

          This is what I have now:
          [code=actionscri pt]var variables:URLVa riables = new URLVariables();
          var varSend:URLRequ est = new URLRequest();
          varSend.url = "http://www.thefreightr ateco.com/dev/contactus.aspx" ;
          varSend.method = URLRequestMetho d.POST;
          varSend.data = variables;
          var varLoader:URLLo ader = new URLLoader();
          varLoader.dataF ormat = URLLoaderDataFo rmat.VARIABLES;
          varLoader.addEv entListener(Eve nt.COMPLETE, sendEmail);


          stop();

          stage.focus = tbName;


          send_btn.addEve ntListener(Mous eEvent.CLICK, sendEmail);

          function sendEmail(event :MouseEvent):vo id
          {
          variables.tbNam e = tbName.text;
          variables.tbEma il = tbEmail.text;
          variables.tbBod y = tbBody.text;
          trace(varSend.d ata);
          varLoader.load( varSend);
          //varLoader.dataF ormat = URLLoaderDataFo rmat.VARIABLES;
          }[/code]

          The trace shows the right data and an error message:
          Code:
          tbEmail=Bob%40Bob%2Ecom&tbBody=Body%20of%20email&tbName=Bob
          Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
          	at Error$/throwError()
          	at flash.net::URLVariables/decode()
          	at flash.net::URLVariables$iinit()
          	at flash.net::URLLoader/flash.net:URLLoader::onComplete()
          How do I append the query string to the URL?

          Comment

          • xNephilimx
            Recognized Expert New Member
            • Jun 2007
            • 213

            #6
            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&pa ram2=val2";

            Your code would be like this now:

            [CODE=actionscri pt]
            stop();
            var variables:URLVa riables = new URLVariables();
            var varSend:URLRequ est = new URLRequest("htt p://www.thefreightr ateco.com/dev/contactus.aspx" );
            varSend.method = URLRequestMetho d.POST;
            var varLoader:URLLo ader = new URLLoader();
            varLoader.dataF ormat = URLLoaderDataFo rmat.VARIABLES;
            varLoader.addEv entListener(Eve nt.COMPLETE, onComplete);

            stage.focus = tbName;


            send_btn.addEve ntListener(Mous eEvent.CLICK, sendEmail);

            function onCompete(e:Eve nt):void {
            trace('The email has been sent');
            //you can add eny other functionality to actually tell the user
            //I'm just tracing a legend
            }

            function sendEmail(event :MouseEvent):vo id
            {
            variables.decod e("tbName=" + tbName.text + "&tbEmail=" ) + tbEmail.text + "&tbBody=" + tbBody.text);
            varSend.data = variables;

            trace(varSend.d ata);

            varLoader.load( varSend);
            }[/CODE]

            Try that and tell me how it worked

            Best regards
            The_Nephilim

            Comment

            • rrocket
              New Member
              • Aug 2007
              • 116

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

              Thanks,
              RRocket

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                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:
                [code=actionscri pt]var variables:URLVa riables = new URLVariables();
                var varSend:URLRequ est = new URLRequest();
                varSend.url = "http://www.thefreightr ateco.com/dev/contactus.aspx" ;
                varSend.method = URLRequestMetho d.POST;
                varSend.data = variables;
                var varLoader:URLLo ader = new URLLoader();
                varLoader.dataF ormat = URLLoaderDataFo rmat.VARIABLES;
                varLoader.addEv entListener(Eve nt.COMPLETE, sendEmail);


                stop();

                stage.focus = tbName;


                send_btn.addEve ntListener(Mous eEvent.CLICK, sendEmail);

                function sendEmail(event :MouseEvent):vo id
                {
                variables.tbNam e = tbName.text;
                variables.tbEma il = tbEmail.text;
                variables.tbBod y = tbBody.text;
                trace(varSend.d ata);
                varLoader.load( varSend);
                //varLoader.dataF ormat = URLLoaderDataFo rmat.VARIABLES;
                }[/code]

                The trace shows the right data and an error message:
                Code:
                tbEmail=Bob%40Bob%2Ecom&tbBody=Body%20of%20email&tbName=Bob
                Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
                	at Error$/throwError()
                	at flash.net::URLVariables/decode()
                	at flash.net::URLVariables$iinit()
                	at flash.net::URLLoader/flash.net:URLLoader::onComplete()
                How do I append the query string to the URL?
                Try this out:

                [code="actionscr ipt"]
                function EmailPost(name, email, body)
                {
                var postData = new LoadVars();

                //Load up all the variables you want to POST
                postData.tbName = name;
                postData.tbBody = body;
                postData.tbEmai l = email;

                postData.send(" http://www.thefreightr ateco.com/dev/contactus.aspx" , "_self","POST") ;
                }
                [/code]

                Comment

                • xNephilimx
                  Recognized Expert New Member
                  • Jun 2007
                  • 213

                  #9
                  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

                  Originally posted by Motoma
                  Try this out:

                  [code="actionscr ipt"]
                  function EmailPost(name, email, body)
                  {
                  var postData = new LoadVars();

                  //Load up all the variables you want to POST
                  postData.tbName = name;
                  postData.tbBody = body;
                  postData.tbEmai l = email;

                  postData.send(" http://www.thefreightr ateco.com/dev/contactus.aspx" , "_self","POST") ;
                  }
                  [/code]

                  Comment

                  • xNephilimx
                    Recognized Expert New Member
                    • Jun 2007
                    • 213

                    #10
                    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:

                    [CODE=actionscri pt]
                    send_btn.addEve ntListener(Mous eEvent.CLICK, onClick);

                    function onClick(e:Mouse Event):void {
                    var src:String = "tbName=" + tbName.text + "&tbEmail=" + tbEmail.text + "&tbBody=" + tbBody.text;
                    var vars:URLVariabl es = new URLVariables(sr c);
                    var request:URLRequ est = new URLRequest('htt p://www.thefreightr ateco.com/dev/contactus.aspx' );
                    request.method = URLRequestMetho d.POST;
                    request.data = vars;

                    var loader:URLLoade r = new URLLoader();
                    loader.dataForm at = URLLoaderDataFo rmat.TEXT;

                    loader.load(req uest);
                    }
                    [/CODE]

                    I did this in Flex and it's working perfectly.

                    Best regards,
                    The_Nephilim

                    Comment

                    Working...