A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: Need help! getURL not working...

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    10

    Need help! getURL not working...

    Hello , I'm trying to make a simple form that uses a input text box to redirect to a specific url. However it doesnt work at all. I have a input box and a button with the code bellow.
    Here is my code:

    on (release, keyPress "<Enter>") {
    if (input == "boo") {
    getURL("x3.jpg", "_blank");
    if (input == "bii") {
    getURL("http://www.google.ro", "_blank");

    }
    } else {
    prevFrame();
    }

    }

    the text input box variable is input. When i click the button it skips to the prevframe no matter if the word typed is boo or bii. It doesn't redirect me either to x3.jpg or http://www.google.ro , it skips to the prevframe. If i remove prevframe nothing happens.
    I need to use about 500 words that redirects to 500 url , in my case a picture stored on the server.
    If i change prevFrame(); with getURL("x3.jpg", "_blank"); When i click the button it skips to x3.jpg no matter of the word typed in the box.
    As i said i need to use about 500 words . if you know a better way to do this i would appreciate your effort. i could have used a php file but my server doesn't support php or mysql. I think that xml and txt files are supported , but i'm not sure.
    Thanx in advance for your help!

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    I would have said use switch case, but if you have 500 of these pairs, treat them as such: pairs? as in variables value pairs. That list could be in any format you can load.
    boo="x3.jpg";
    bii="http://www.google.ro";

    then, in flash, once the list is loaded and without any conditional statements:

    actionscript Code:
    var myUrl:String = eval(this.input);
    getURL(myUrl);

    gparis

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    I just saw you also need a validation. Sorry, scrap the previous code (still treating the data in value pairs, though).

    Another way that allows validation of the input against your list. Use an Array. Example with your 2 pairs:

    actionscript Code:
    var myUrl:String = "";
    myList = new Array();
    myList[0] = {ur:"http://www.google.ro", val2:"bii"};
    myList[1] = {ur:"x3.jpg", val2:"boo"};
    //etc..

    Place that code in your first frame. Then the validation you call from the button:
    if the value "val2" in the myList array equals the input, assign the value of "ur" to myUrl. Then, the same call than before.
    Here's a (tested) working code:

    actionscript Code:
    stop();
    var myUrl:String = "";
    myList = new Array();
    myList[0] = {ur:"http://www.google.com", val2:"boo"};
    myList[1] = {ur:"http://www.yahoo.com", val2:"bii"};
    myList[2] = {ur:"http://www.flashkit.com", val2:"bah"};
    //etc..
    function validate() {
        for (i=0; i<myList.length; i++) {      
            if (myList[i]["val2"] == this.input) {
                myUrl = myList[i]["ur"]
                getURL(myUrl, "_blank");
            } else {
                prevFrame();
            }
        }
    }
    button.onPress = function() {
        validate();
    };

    gparis

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    10
    Thank you for your help . I used the code , but it doesn't work. the text input box has the var input, but when i click the button nothing happens. I use flash 8 , as2 , and flash cs 4.

  5. #5
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    try testing it in a browser or on your server
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  6. #6
    Junior Member
    Join Date
    Mar 2010
    Posts
    10
    Already done that . i get an eror when i try to put the validation on the button.

    button.onPress = function() {
    validate();
    };
    Is on the button ,

    stop();
    var myUrl:String = "";
    myList = new Array();
    myList[0] = {ur:"http://www.google.com", val2:"boo"};
    myList[1] = {ur:"http://www.yahoo.com", val2:"bii"};
    myList[2] = {ur:"http://www.flashkit.com", val2:"bah"};
    //etc..
    function validate() {
    for (i=0; i<myList.length; i++) {
    if (myList[i]["val2"] == this.input) {
    myUrl = myList[i]["ur"]
    getURL(myUrl, "_blank");
    } else {
    prevFrame();
    }
    }
    }

    Is on the frame .
    Is it wrong?

  7. #7
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    button.onPress = function() {
    validate();
    };
    Is on the button
    It is wrong. Everything goes in a frame. 'button' is your button's instance name.

    gparis

  8. #8
    Junior Member
    Join Date
    Mar 2010
    Posts
    10
    Ok, so everything is in the frame. i named the button , button , and still nothing happens. The text input's var is input. What im doing wrong?

  9. #9
    Junior Member
    Join Date
    Mar 2010
    Posts
    10
    Ok its working , but not as it should work. if i type boo it stil goes to prevframe. No matter of what i type it goes to prevframe. What is wrong with it?

  10. #10
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Here it is, corrected:

    Actionscript Code:
    stop();
    var myUrl:String = "";
    var input:String ="";
    myList = new Array();
    myList[0] = {ur:"http://www.google.com", val2:"boo"};
    myList[1] = {ur:"http://www.yahoo.com", val2:"bii"};
    myList[2] = {ur:"http://www.flashkit.com", val2:"bah"};
    //etc..
    function validate() {
        myUrl = "";
        for (i=0; i<myList.length; i++) {      
            if (myList[i]["val2"] == this.input) {
                myUrl = myList[i]["ur"];
            }
        }
    }
    function getMyUrl() {
        if (myUrl == "") {
            prevFrame();
        } else {
            getURL(myUrl, "_blank");
           
        }
    }
    button.onPress = function() {
        validate();
        getMyUrl();
    };

    gparis

  11. #11
    Junior Member
    Join Date
    Mar 2010
    Posts
    10
    Still not working. this thing its driving . for 2 days i'm trying to make it work. It skips back to the prevframe no matter what i type. The input box var is input. tryed with instace name input , it doesn't work. On the server the same story.

  12. #12
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    find .fla attached. CS3 AS2

    gparis
    Attached Files Attached Files

  13. #13
    Junior Member
    Join Date
    Mar 2010
    Posts
    10
    Thank you for the .fla file. the file works without a problem , but when i put the code in my fla it stops working. I think it is something in my fla file that blocks it. When i enter the code and click the button it goes back to the prevframe. yours works fine, mine doesn't. Is there any other way to do this, maybe with the help of an external file?

  14. #14
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Of course you could have the myList array content as an external file that you would split back into an array similar to the one in my example. But that wouldn't change 'the way', just the ease of editing without opening the .fla.

    gparis

  15. #15
    Junior Member
    Join Date
    Mar 2010
    Posts
    10
    I see. if i put the code at the begining of the movie , it works. If i put it where i need it, it doesn't work. Ill try to put it between other layers ,maybe that will work. thank you for your help , and ill keep you up to date.
    I also created a new movie with just the code , and it works just fine.
    Thank you ,
    Cezar

  16. #16
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    The instance of the button and the textfield with var input have to be present on that specific keyframe on your timeline where the code is. The layer's order wouldn't change a thing.

    gparis

  17. #17
    Junior Member
    Join Date
    Mar 2010
    Posts
    10
    It's working!!! I can't believe it , but it's working. Thank you for your time and all your help. you are a great man!

  18. #18
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Don't know if i'm great but i'm definitely not a man ;-)

    gparis

  19. #19
    Junior Member
    Join Date
    Mar 2010
    Posts
    10
    Oh , I'm sorry. My apologies! I had no ideea...Thank you again!

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