A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: auto fire link from text file

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    8

    Lightbulb auto fire link from text file

    Hi - I have a flash movie that loads random text (with specific href attached) from a .txt file.

    This is the user interaction process at the moment.

    1. user clicks on movie
    2. random text is loaded into movie from a .txt file
    3. the random text has an href around the text loaded into the flash movie
    4. user clicks random text to take them to a specific page (associated to the random text loaded) on my website.

    At the moment, the user has to click the flash movie twice before it sends them to the correct page. Once to activate the random text being loaded into the flash movie, and a 2nd time to link through to my specific page.

    My question:
    IS there a way to load the random text into the movie after initial click, pausing for 10 seconds, and then auto fire the href associated to the random text - thus sending the user to my specific page IN ONE CLICK.

    I am losing follow through users at present as they have to click the movie twice to get to the correct page, if I am able to auto fire the href so that the user only has to click once, this should reduce the amount of user interaction and also reduce the drop off rate.

    Many thanks for any help you can give.
    Jahjah99

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Post the code to load the text from .txt file, and also the text that is loaded into Flash. You can use setInterval to execute a function after x amount of milliseconds - just post your code, and I'll write a code for you
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    8
    Hey Nig - Thanks very much for your offer of writing the extra code. I very much appreciate it.

    Here is the code I am using at the moment, it has been cobbled together from bits I have foound on the web.

    Loading the .txt file.

    Actionscript Code:
    /****************************************
    **Random Quotes Script*******************
    ****************************************/

    /*Quotes.txt.htmlText = true;*/

    ranQuote = new LoadVars();
    ranQuote.onLoad = function(success) {
    if (success) {
    RanNum = Math.ceil(Math.random()*100);
    ran = this["quote"+RanNum];
    quote_txt.htmlText = ran;
    /*quote_txt.htmlText = true;*/
    }
    else {
    quote_txt.htmlText = "The text failed to load due to an error";
    }
    }
    ranQuote.load("http://www.mydomain.com/Quotes.txt");
    System.security.allowDomain('http://www.mydomain.com');

    Here is a sample of the .txt file contents. It is over 100 lines long so I wont add it all.

    Actionscript Code:
    &quote1=<a href="http://www.mydomain.com/folder1/page1.html">random text here 1</a>&
    &quote2=<a href="http://www.mydomain.com/folder2/page2.html">random text here 2</a>&
    &quote3=<a href="http://www.mydomain.com/folder1/page2.html">random text here 3</a>&
    &quote4=<a href="http://www.mydomain.com/folder2/page1.html">random text here 4</a>&
    &quote5=<a href="http://www.mydomain.com/folder3/page1.html">random text here 5</a>&
    &quote6=<a href="http://www.mydomain.com/folder3/page2.html">random text here 6</a>&
    &quote7=<a href="http://www.mydomain.com/folder3/page3.html">random text here 7</a>&
    &quote8=<a href="http://www.mydomain.com/folder1/page3.html">random text here 8</a>&
    &quote9=<a href="http://www.mydomain.com/folder2/page3.html">random text here 9</a>&
    &quote10=<a href="http://www.mydomain.com/folder4/page1.html">random text here 10</a>&

    etc ...

    If you need any more information - Let me know and I will dig deeper!
    Thanks again.

    Jahjah99

    Quote Originally Posted by Nig 13 View Post
    Post the code to load the text from .txt file, and also the text that is loaded into Flash. You can use setInterval to execute a function after x amount of milliseconds - just post your code, and I'll write a code for you

  4. #4
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Here is the edited code for the 'if' part of your code:

    Actionscript Code:
    if (success) {
        RanNum = Math.ceil(Math.random()*100);
        ran = this["quote"+RanNum];
        quote_txt.htmlText = ran;
        function autoFire(){
            link = ran.split("'");
            getURL(link[1], "_blank");
        }
        setTimeout(autoFire, 1000);
    }

    To make this work, you'll have to edit all " from the a href to ' and you can easily do that by using a text editor, and use Replace (Notepad: Edit->Replace), and type in " in what it should search for, and what it should replace with ' and then press Replace All
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  5. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    8
    HI - Thanks for writing that, unfortunately for me it didn't work!

    I wonder if the reason for it not working is a security issue - here is my thinking and the current structure:

    Server 1:
    SWF (with ActionScript)
    Quotes.txt
    Referenced html pages.

    Server 2:
    Html page with (below) code referencing SWF movie on server 1.

    PHP Code:
    object width="200" height="247">
             * *<
    param name="movie" value="http://www.myserver1.com/mySWF.swf"></param>
             * *<
    param name="allowFullScreen" value="true"></param>
             * *<
    param name="allowscriptaccess" value="always"></param>
             * *<
    embed src="http://www.myserver1.com/mySWF.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="200" height="247"></embed>
             </
    object

    I came across a security issue before (Nig you pointed this out) with having the SWF and Quotes.txt on server 1 and referencing the SWF from an Html page on server 2. I managed to overcome this issue using this post:
    http://board.flashkit.com/board/show...10#post4291010

    So even though I managed to overcome the security issue before, I am wondering if the autofire function within the script is causing another security problem as it is being fired by code rather than a user clicking a link.

    I would be interested to know your thoughts.

    Here is my code now being used after your re-write (thanks again for that):

    ActionScript:
    PHP Code:
    ranQuote = new LoadVars();
    ranQuote.onLoad = function(success) {
    if (
    success) {
        
    RanNum Math.ceil(Math.random()*100);
        
    ran this["quote"+RanNum];
        
    quote_txt.htmlText ran;
        function 
    autoFire(){
            
    link ran.split("'");
            
    getURL(link[1], "_blank");
        }
        
    setTimeout(autoFire1000);
    }
    else {
    quote_txt.htmlText "The text failed to load due to an error";
    }
    }
    ranQuote.load("http://www.mydomain.com/Quotes.txt");
    System.security.allowDomain('http://www.mydomain.com'); 
    Quotes.txt:
    PHP Code:
    &quote1=<a href='http://www.mydomain.com/folder1/page1.html'>random text here 1</a>&
    &
    quote2=<a href='http://www.mydomain.com/folder2/page2.html'>random text here 2</a>&
    &
    quote3=<a href='http://www.mydomain.com/folder1/page2.html'>random text here 3</a>&
    &
    quote4=<a href='http://www.mydomain.com/folder2/page1.html'>random text here 4</a>&
    &
    quote5=<a href='http://www.mydomain.com/folder3/page1.html'>random text here 5</a>&
    &
    quote6=<a href='http://www.mydomain.com/folder3/page2.html'>random text here 6</a>&
    &
    quote7=<a href='http://www.mydomain.com/folder3/page3.html'>random text here 7</a>&
    &
    quote8=<a href='http://www.mydomain.com/folder1/page3.html'>random text here 8</a>&
    &
    quote9=<a href='http://www.mydomain.com/folder2/page3.html'>random text here 9</a>&
    &
    quote10=<a href='http://www.mydomain.com/folder4/page1.html'>random text here 10</a>&

    etc ... 
    Kind regards Jahjah 99

  6. #6
    Junior Member
    Join Date
    Sep 2011
    Posts
    8
    I also tried changing the:

    PHP Code:
    getURL(link[1], "_blank"); 
    to

    PHP Code:
    getURL(link[1]); 
    To see if opening a new window was part of the issue, but no improvement. After clicking; the movie plays, produces the Quote and then does not autofire. The link still works if clicked by user interaction.

    Hope this helps some more.
    Thanks again - Jahjah 99

  7. #7
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Diagnose the problem!

    Make a Dynamic Text field in your Flash file, give it a Variable name of my_txt, and then edit your code to this:

    Actionscript Code:
    if (success) {
        RanNum = Math.ceil(Math.random()*100);
        ran = this["quote"+RanNum];
        quote_txt.htmlText = ran;
        function autoFire(){
            link = ran.split("'");
        my_txt = link;
            getURL(link[1], "_blank");
        }
        setTimeout(autoFire, 1000);
    }

    Check if my_txt displays the URL link after 1 second, and reply

    EDIT: WOOT, 500th post
    Last edited by Nig 13; 10-03-2011 at 09:56 AM.
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  8. #8
    Junior Member
    Join Date
    Sep 2011
    Posts
    8
    hi - It didn't show the my_txt either.

    I placed the my_text dynamic field in the same movie clip as the AS.
    so the structure is:

    Main Time line:
    button to fire movieclip 1

    AS location.
    Main timeline/mc_1/mc_2 (AS here [fired from action sat in timeline])

    I also tried adding the my_txt dynamic field to the main time line and appeared up there either.

    Many thanks again Nig. I really do appreciate you knowledge. Karma points to you for helping.
    Last edited by jahjah99; 10-03-2011 at 09:30 AM.

  9. #9
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    No problem, happy to help

    As for the problem, areyou sure it was the dynamic text field's var(iable) name and not instance name? Also, if you place it on main timeline, add _root to my_txt: _root.my_txt
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  10. #10
    Junior Member
    Join Date
    Sep 2011
    Posts
    8
    Hello - You were right - I did add my_txt as an instance name and not a variable. This has now been changed, but still it does not flag up the link in the dynamic field.

    I am sorry to take up so much of your time.

    Regards - jahjah99

    -- If it makes it easier and wont take up too much of your time, I could upload the FLA onto a server for you.
    Last edited by jahjah99; 10-03-2011 at 10:15 AM.

  11. #11
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    -- If it makes it easier and wont take up too much of your time, I could upload the FLA onto a server for you.
    Please do so
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  12. #12
    Junior Member
    Join Date
    Sep 2011
    Posts
    8
    Thanks - Sent you a PM with link.

    Regards
    jahjah99
    Last edited by jahjah99; 10-03-2011 at 12:23 PM.

  13. #13
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Change code to this:

    For some reason, the function wasn't working, because it wasn't properly created when in the LoadVars, so I made it outside, and adjusted the code abit as well, so you don't have to change quotes to apostrophes of the links, change the whole code to this:

    Actionscript Code:
    function autoFire(){
            link = ran.split("\"");
            getURL(link[1], "_blank");
    }

    ranQuote = new LoadVars();
    ranQuote.onLoad = function(success) {
        if (success) {
            RanNum = Math.ceil(Math.random()*100);
            ran = this["quote"+RanNum];
            quote_txt.htmlText = ran;
            setTimeout(autoFire, 1000);
        } else {
            quote_txt.htmlText = "The text failed to load due to an error";
        }
    }

    ranQuote.load("http://www.mydomain.com/Quotes.txt");
    System.security.allowDomain('http://www.mydomain.com');
    Last edited by Nig 13; 10-04-2011 at 06:56 AM. Reason: Sorry, removed the link as requested ;)
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  14. #14
    Junior Member
    Join Date
    Sep 2011
    Posts
    8
    HI - I have added the new code you wrote - It is all working - You Are A Star.
    Many thanks for helping me out with this.

    Regards
    Jahjah99

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