A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Dynamic SWF play based on current URL?

  1. #1
    Member
    Join Date
    Sep 2008
    Location
    Chesapeake, VA
    Posts
    35

    Question Dynamic SWF play based on current URL?

    I have a SWF banner that has 12 MC's lined up to start on MC1 and play sequentially. play MC1 > MC2 >...>MC12 then back to MC1 and loop.

    Well now I have a request to make it play MC3 (example) when I am on a specific page of the site and then loop back to MC1 and start over. As well as the same idea for another page of the site.

    currently I have a 2 frame FLA file with the first frame ActionScript looking roughly like this (to kick start the MC's into motion)

    play MC1
    stop MC2
    stop MC3
    stop MC4
    ...

    Then the next frame of the time line is a STOP();

    from here the individual MC timelines determine the behavior of the MC's

    So does it make sense that if I can grab the URL (www.XYZ.com./page3.html) that I could use an IF/ELSE statement to play a different opening script? like this (I know syntax is wrong)...


    Actionscript Code:
    if URL(page2.html)
    {
    stop MC1
    PLAY MC2
    stop MC3
    stop MC4
    ...
    }
    if URL(page3.html)
    {
    stop MC1
    stop MC2
    PLAY MC3
    stop MC4
    ...
    }

    ...

    else
    {
    PLAY MC1
    stop MC2
    stop MC3
    stop MC4
    ...
    }

    If this sounds right, does anyone have an idea as to how to do this? I have not pulled URL data before and would love to see this work.

    Thank you.
    At first you do not succeed,
    Deny you were ever trying.

  2. #2
    Member
    Join Date
    Sep 2008
    Location
    Chesapeake, VA
    Posts
    35
    75 views and nobody has a clue. Oh well. I will start constructing some code myself. I hope I can get it to work. When I do, I will post the code to the site here for all.
    At first you do not succeed,
    Deny you were ever trying.

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    1
    I figured it out, you need to read the url of the page that you are on and then use an "if, then" to make your movie clip or anything else do whatever you want.

    To read the url:
    import flash.external.*;
    var urlPath;
    function geturlhttp() {
    urlPath = ExternalInterface.call("window.location.href.toStr ing");

    }
    geturlhttp();

    And then you make an action based on the result of that url:

    if (urlPath == "http://yourpage.com") {
    gotoAndPlay(3);
    }else{
    }
    stop();

    I hope it helps

    Ps: I noticed on the preview of this reply that the word String has an space on the middle, I don't know if this would remain on the final reply but just in case, be careful with that

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    Como hacer que un swf (flash) tenga diferentes comportamientos segun la direccion url

    Y para los q no hablan ingles, para lograr que un swf reaccione de diferntes maneras segun la url en la que se encuentra (por ejemplo si fuera un menu) se debe primero leer el url donde se esta y luego usaruna funcion "if, then" para lograr lo que se quiera

    Primero se lee el url:

    import flash.external.*;
    var urlPath;
    function geturlhttp() {
    urlPath = ExternalInterface.call("window.location.href.toStr ing");

    }
    geturlhttp();

    Y luego se hace una accion basandose en si la url es una en particlar o no:

    if (urlPath == "http://yourpage.com") {
    gotoAndPlay(3);
    }else{
    }
    stop();

    Espero que les sirva

    pd: cuando hacia esta respeuesta note en la previsualizacion que pone un espacio en la palabra string, no se si lo deje ne la respuesta que publique pero por si al caso tengan cuidado no sea que les de error

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    I would probably use good ol' flashvars to pass in some info rather than calling out via externalinterface.
    So the embedding would contain
    <embed src="movie.swf" flashvars="page=xxx" ....

    BTW: this would mean that your code does not have to care whether the real url looks like somesite.com, www.somesite.com or maybe localhost

    Musicman
    Last edited by Musicman; 02-28-2011 at 12:47 AM.

Tags for this Thread

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