dcsimg
A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: I have AS2 but what is the AS3 equivalent for mailto.

  1. #1
    Member
    Join Date
    Sep 2009
    Posts
    35

    I have AS2 but what is the AS3 equivalent for mailto.

    Hi

    I have this code for people to fill out some forms and press submit which loads up the email program with all the fields (email, subject, message) filled in from what they entered in the forms. this is the code

    on (release) {
    getURL("mailto:" + to + "?subject=" +subject+ "&body=" + body);
    }

    Typically I wanted a scroll bar component for the message bit but that only works in AS3 where the code is for AS2, does anyone know the AS3 version please.

    Thanks

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    mailto is a url protocol (like http), and is not specific to as2. It works in as3, javascript, and plain html. Anywhere a url works.

    The AS3 equivalent of that code is:
    Code:
    addEventListener(MouseEvent.MOUSE_UP, openEmail);
    function openEmail(e:Event):void{
      navigateToURL(new URLRequest("mailto:" + to + "?subject=" +subject+ "&body=" + body));
    }

  3. #3
    Member
    Join Date
    Sep 2009
    Posts
    35
    Hi flax

    thanks for you help, where would I put this code in AS3? I have just found out that you can't put actions to buttons any more. I have put your code onto a separate layer in the form mc only to get this when tested.

    1120: Access of undefined property body.navigateToURL(new URLRequest("mailto:" + to + "?subject=" +subject+ "&body=" + body));

    I seem to of got that error for 'subject' and 'message' as well

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    navigateToURL is a function in the flash.net package. Import it and use it on its own.

    The event listener should be added to the button you want to react. So:
    Code:
    import flash.net.*;
    
    aButton.addEventListener(MouseEvent.MOUSE_UP, openEmail);
    function openEmail(e:Event):void{
      navigateToURL(new URLRequest("mailto:" + to + "?subject=" +subject+ "&body=" + body));
    }
    where aButton is your button.

  5. #5
    Member
    Join Date
    Sep 2009
    Posts
    35
    Sorry i'm being really thick here, is flash.net something I have to download and install?

    I tried that code again, and still got the same error message, including a new on for the button. There seem to be a lot of undefined properties, and I have no idea what any of it means. noob. sorry

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    No, flash.net is already included.

    The error message you are getting says that body is undefined. Where have you defined it? It must be in the same scope. Subject will probably also be undefined in this scope, and maybe "to" as well.

  7. #7
    Member
    Join Date
    Sep 2009
    Posts
    35
    Oh ok. phew.

    Ok this what I have, I have two dynamic text fields for the user to fill out an email address and a subject, I also have a multi lined text box for the user to put in the message. All this is contained in a move clip called 'form' this is placed on scene 1.

    As the fields are blank when tested, would filling in the forms during the test get rid of the errors?

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    If this code is in the main timeline, then you will have to go through form and the textfields to get the text.

    Filling in the forms alone would not get rid of the errors, because the errors are that flash has no idea what you're talking about.

    Code:
    import flash.net.*;
    
    aButton.addEventListener(MouseEvent.MOUSE_UP, openEmail);
    function openEmail(e:Event):void{
      navigateToURL(new URLRequest("mailto:" + form.to.text + "?subject=" +form.subject.text+ "&body=" + form.body.text));
    }
    again, this assumes aButton is a child of the movieclip which has this code.

  9. #9
    Member
    Join Date
    Sep 2009
    Posts
    35
    Sorry, I bet you wished you never answered now, I'm still getting the same errors!
    I have place the submit button in the same movie clip as the dynamic text boxes. should I just put all the elements on the main stage and forget the movie clip? or would it make no difference?

    the annoying thing is the as2 code worked fine, just the scroll bar component didn't work in As2. frustrating!

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    If the submit button is in the same clip as the text boxes, then the only thing that would change is the line with addEventListener. It would have to be
    Code:
    form.aButton.addEventListener(MouseEvent.MOUSE_UP, openEmail);
    I think your issues are all scope related. From what I can gather, your movie structure looks like this
    Code:
    root
      form
        button
        textfield
        textfield
        textfield
    And the code is on the root. Since you're using frames and scenes, you have to be sure that the relevant items actually exist when they are referred to.

  11. #11
    Member
    Join Date
    Sep 2009
    Posts
    35
    Arggghhh still no joy, would it make any difference if I cave the text fields instance names of variables? All I'm getting is the error message and I don't know why. way back at the start, I had a simple key press 'E' which would bring up the mail program with the email address and a hello Paul message written in. that worked fine, but this, I have no clue

  12. #12
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The code I posted assumed that your textfields had instancenames of "to", "subject" and "body".

  13. #13
    Member
    Join Date
    Sep 2009
    Posts
    35
    Ahhhh, now we are getting somewhere, still a couple of issues though, firstly, all the forms are automatically filled in with: level10.instance1.message and I still get an error saying: The class or interface 'Event' could not be loaded. function openEmail(e:Event):void{

    but we are very close, any ideas?

    Many thanks in advance

  14. #14
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    level10? Is that BS still around? UGLY.

    I thought Event was automatically included. Since it appears not to be, up near the other imports add
    Code:
    import flash.events.Event;
    Any time you have one of those class not found type errors, you may have to import the class.

  15. #15
    Member
    Join Date
    Aug 2007
    Posts
    47
    Sorry to bump an old-ish thread, but I'm wondering if the above code needs any backend PHP or ASP, or should it work fine? I'm using it without PHP or ASP and haven't got it working yet, is all...
    Cheers.

  16. #16
    Member
    Join Date
    Aug 2007
    Posts
    47
    Sorry! Scratch my last message. It works now! But if anyone can tell me why a KeyboardEvent listener would detect all keystrokes apart from the ENTER key, I'd be mighty thankful. I tried changing the text field from single to multiline, and disabling keyboard shortcuts. Hmm....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center