Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trying to convert as1 code to as3

Guest
Oct 26, 2013 Oct 26, 2013

Hi,

I have to convert a as1 site to as3.

The only part of the whole thing that i'm not sure of is this:

          on(release){

                    loadvariables ("save.aspx?cmd=addemail&adresse=" add string(adresse.text),this)    

                    Object.prototype.alert = function (message) {

                          getURL("javascript:alert('"+message+"')");

                    }

               alert("We received your email, thank you.");

               adresse.text="";

          }

It's basically a newsletter subscription box done in as1.

Will the same code work if I only include it in a as3 MouseEvent.CLICK like this:

function btn_click(event:MouseEvent):void {

          loadvariables ("save.aspx?cmd=addemail&adresse=" add string(adresse.text),this)    

          Object.prototype.alert = function (message) {

                getURL("javascript:alert('"+message+"')");

          }

     alert("We received your email, thank you.");

     adresse.text="";

}

...?

Thanks

TOPICS
ActionScript
746
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 26, 2013 Oct 26, 2013

No, you'll need to convert the rest of the function code to AS3 as well.  You'll probably need to look into using the URLLoader class for the data and the ExternalInterface class for the javascript alert.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 28, 2013 Oct 28, 2013

Thanks Ned for guiding me.

I looked into both (URLLoader / ExternalInterface) and I came up converting the original As1 code:

on(release){

loadvariables ("save.aspx?cmd=addemail&adresse=" add string(Adresse.text),this)    

Object.prototype.alert = function (message) {

getURL("javascript:alert('"+message+"')");

}

alert("We received your email, thank you.");

Adresse.text="";

}

into this As3 code:

lbl.text = "ExternalInterface.available: " + ExternalInterface.available;

var myLoader:URLLoader;

var myVars:URLVariables;

var Response:String = "We received your email, thank you.";

//////////////////////////////////////////////////////////////////////////////This is my button

button.enabled = ExternalInterface.available;

button.addEventListener(MouseEvent.CLICK, sendEmail);

/////////////////////////////////////////////////////////////////////This is Onclick

function sendEmail(e:MouseEvent):void

{

    myLoader = new URLLoader();

    myVars = new URLVariables();

    myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

    myVars.email = Adresse.text; // Text from textfield

    myLoader.data = myVars;

    myLoader.addEventListener(Event.COMPLETE, messageSent, false, 0, true);

    myLoader.load(new URLRequest("save.aspx?cmd=addemail&adresse="+myVars.email));

}

///////////////////////////////////////////////////////////////This is the response

function messageSent(e:Event):void

{

    ExternalInterface.call("alert", Response);

    Adresse.text="";

}

The thing is that I don't have access to the server and aspx file and i'd just like to make sure i'm heading in the right direction so far.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 28, 2013 Oct 28, 2013
LATEST

I'd say the direction is fine... but you will need to get the server in the loop to work it out.  Since you are sending data to the file as part of the url string, I don't know that the myVars is necessary, or alternatively that the url string is not necessary and the data can be sent as the myVars data element (aka myLoader.data). 

I have not worked with asp files so I can't say what needs to exist on that end to process the data.  As a PHP file it would be able to extract the data from the myLoader.data that gets passed.  I am sure asp can probably do the same thing, I just don;t have experience with how to code it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines