Follow @BPSPro

Linking Multiple Websites In A Flash Movie | AS3 Flash Code to Create URL Links

6 Comments RSS Site Feed Author: AITpro Admin
Published: June 28, 2010
Updated: September 29, 2010

The original question was regarding how to link multiple websites (domains and subdomains) from a single Flash movie.  The question was not completely clear so the answer includes general and specific information about website domains and subdomains and the specific AS3 Flash code you would use to create website URL links in Flash.

I think what you are saying is that you have a website domain that has a .swf (Shockwave Flash Movie) either embedded in your website or you have a Full Flash website, meaning the entire website is a SWF. Not 100% sure from your question. In any case it appears you have one current website domain and you want to know how to create some subdomains and link them from the main Flash movie.

5 Individual website domains explanation

If you want 5 individual websites you would of course buy the domain names, setup the folders for each individual website domain from your web hosting account and then add the necessary website files for each individual website domain. To simplify this explanation let’s just say you already own domain0.com and you want to add domain1.com and domain 2.com. In your web host you should see your root directory for domain0. Now to add new website domains to your domain0.com web hosting account you just create folders for example called domain1.com and domain2.com and put the necessary individual website files in each folder for each individual website domain. For simplicity sake let’s say you just add 1 page = index.htm to each individual website domain. So when someone types in www.domain1.com the index.htm file will load / open for that domain.

5 website subdomains explanation

A subdomain is exactly what it sounds like. A sub domain (just a folder) off of the root website domain. In your scenario using domain0.com as the example. A subdomain example would be sub1.domain0.com or domain0.com/sub1. These are both considered subdomains. The only difference is in your root website domain you would either have a folder named sub1.domain0.com or just sub1 directly off of your root website domain.

Since you said the Flash website is only one file I am assuming that you have an SWF that you want to add links to the other websites or maybe actually just 5 web pages. I’m going to assume that you have the actual Flash program with an .fla file so that you can create an SWF file from the .fla Flash file and not just have an SWF that has already been created from a Flash .fla file.

This is the AS3 Flash code you would use to create URL links:

function gotoquoteform(event:MouseEvent):void {
var targetURL:URLRequest = new URLRequest("http://www.ait-pro.com/flash-mss-movie/");
navigateToURL(targetURL, "_self");
}
clickMeBTN.addEventListener(MouseEvent.CLICK, gotoquoteform);

Old school method:  You need to create a button in your Flash movie and then within the button Timeline frame you would add the Actionscript code (AS3 code) above to add your URL link.  For multiple links you would just duplicate the AS3 code for each individual button and URL that you wanted to add to the Flash movie.

New school method:  Use Sprites and Loader to create the button dynamically.

Good luck!

Question was asked again with additional infomation:

I answered your other question that was very similar to this one regarding linking 5 different flash websites together. The way you phrased this question now makes me think that you are trying to create something like a footer link for these 5 Flash websites so that they will all be linked back to your main website. Something like a Website Design by…. link back to your website???

This is the AS3 code for CS4 that you use to create links from a Flash button or any symbol (a symbol in Flash is just the name for a graphic that Flash recognizes and can be further customized into a Flash Movie Clip) within Flash. The AS3 code would go in the Actions Frame (you just open the Actions panel and add the code into that frame, which then creates an Actions Frame) of the beginning frame of whatever symbol, text or button within your Flash movie.

function gotoquoteform(event:MouseEvent):void {
var targetURL:URLRequest = new URLRequest("http://www.ait-pro.com/flash-mss-movie/");
navigateToURL(targetURL, "_self");
}
clickMeBTN.addEventListener(MouseEvent.CLICK, gotoquoteform);

On importing a PSD or other jpg, gifs, pngs, etc etc from Photoshop to the Flash library of your particular Flash movie you have probably already noticed that only the images are imported and no link code. That is because the linking code used in Photoshop is HTML. Flash uses AS3 so the link code is totally useless and is stripped out in the import. And you probably already know this, but for anyone who doesn’t when you import graphics into Flash they are limited bitmap graphic files. When you convert those imported graphics into Flash Symbols they then become graphic files that are in essence converted to a format Flash can “work” with in more advanced ways. A graphic within Flash must be a Symbol before it can me made into a Movie Clip. This is in laymans terms, but it shows the basic steps of how to work with imported graphic files within Flash.

So anyway the hard part for you would be figuring out the code I have added above. The rest of the Flash steps you may need to figure out are simple and you should have no problem searching for Flash tutorials for each step that you may need to figure out.

Good luck!


Tags: , ,

Categories: Wordpress Tips - Tricks - Fixes

6 Comments to “Linking Multiple Websites In A Flash Movie | AS3 Flash Code to Create URL Links”


  1. Antonio says:

    no puedo hacer que se vincule mi clip de pelicula con una pagina web,
    quiero que se vincule a una pagina sin ser subida al servidor.

    quisiera recibir ayuda.

    • AITpro says:

      A continuación, se necesita la versión completa de Flash para hacer esto. Usted tendrá que editar el archivo. FLA en Flash y añadir tu enlace.

      Then you will need the full version of Flash to do this. You will need to edit the .fla file in Flash and add your link.

  2. Dale Zki says:

    AS3 Flash SWF code to ‘get/use’ subdomain

    Similar to your june 28 (2010) response “Linking Multi websites…”,
    I am attempting to duplicate an “Aninote”.

    { these websites are no longer available i.e. “dale.youaremighty.com” created by robert blake }
    ~ ref note via web search
    http://freewarewiki.com/AninoteDotCom

    When the ANINOTE.com site was available,
    a users inputs their first and last name (I assume FLASH form,,{this I can do}) ;
    First: Dale
    Last: Zki

    Which created a unique URL…i.e. dale.zki.youraremighty.com
    dale.zki = the subdomain which is then linked and
    used in the SWF (main domain reference).

    The SWF is ready to go,
    using dynamic text to link (at least for now) to a .txt file.

    In summary, how do I link the users ‘name'(subdomain) input to the SWF?

    Ref:
    My sites are hosted on Yahoo,
    built using their Site Builder ex: candozki.com

    While I a comfortable with my FLASH skills,
    I am unsure how & where PHP might be required.

    I look forward to your comments / resource suggestions.

    Dale

    • AITpro Admin says:

      Hi Dale,
      The first issue that will cause limitations and problems with what you are trying to accomplish is Yahoo Site Builder. Most Site builders are designed to do everything for you in an automated way. What this means unfortunately is that you effectively give a site builder program complete control of your website. Typically when you do custom work outside of a site builder, that custom work will either be ignored, overwritten or just not work at all. I have never worked with YSB so i can’t tell you exactly what you will be able to do and not do. I did a general Internet search on YSB and found info that indicates you will not be able to accomplish what you are trying to do on a YSB site because of the YSB limitations.

      Ok now with all of that said. If you decide to create a non site builder website that is not using YSB to create your custom form:
      The best design for the form and what you want to accomplish will use PHP as the server side processor, writing to and creating / appending an XML file that Flash will use to display the end result or output. Flash reads XML to output data and the of course LoadVars() to dynamically output data from a TXT file. You can do everything you want to do with Flash and not use PHP at all of course. That is entirely up to you. I recommend that you go to the republicofcode.com website if you want to do this entirely in Flash. They have all the tuturials that you will need to complete your project. It is also critical that you are using PHP5 on your web host. PHP4 will not allow you to accomplish your goals.

      “Pure” Flash method
      “In summary, how do I link the users ‘name’(subdomain) input to the SWF?”
      With Flash the issues I see that you are facing are: You perform an AddChild for each new subdomain inputted into your Flash form so now you need to just add an additional var or function to write to an external data file. Or you do the whole thing dynamically by sending a new user / new subdomain to a newly generated dynamic movie clip from your static “Form” movie clip. I can only generalize without looking at your actual AS3 coding of course. 😉

      PHP form method instead of “pure” Flash
      The overall concept is that you will create a PHP form or use existing PHP form code and just add XML output (write.xml) coding to your PHP form code. The Flash side of it is that your SWF is pointing to or reading from the XML file (let’s call it a “master” XML file for simple identification of purpose and use) that is dynamically generated by your PHP form script (be careful to focus on append vs overwriting coding). Using this method – as new data is appended to the “master” XML file that PHP is writing too, Flash will be reading or outputting that new data in realtime.

      * You may decide to choose PHP overwrite over append coding if you want to keep the data separate instead of appending to a master list or you can do both – one master XML list for yourself and a single generated XML file per user to process just that one form request.

      Using PHP to write or create an XML file – the most important part of this code is the last few lines of code – you can modify your strings to suit your needs. PHP beginning and closing brackets are not shown below.
      $newusers = array();
      $newusers [] = array(
      'firstname' => 'Robert',
      'lastname' => 'Blake',
      );

      $doc = new DOMDocument();
      $doc->formatOutput = true;

      $r = $doc->createElement( "newusers" );
      $doc->appendChild( $r );

      foreach( $newusers as $newuser )
      {
      $b = $doc->createElement( "newuser" );

      $firstname = $doc->createElement( "firstname" );
      $firstname->appendChild(
      $doc->createTextNode( $newuser['firstname'] )
      );
      $b->appendChild( $firstname );

      $lastname = $doc->createElement( "lastname" );
      $lastname->appendChild(
      $doc->createTextNode( $newuser['lastname'] )
      );
      $b->appendChild( $lastname );

      $r->appendChild( $b );
      }

      echo $doc->saveXML();
      $doc->save("write.xml")

      The Flash side of this will be really simple because all you will need to do in Flash is tell Flash what the name of the XML file is to display.
      AS3 coding example:

      This is just the AS3 code line that points to the XML file or XML master file.
      xml.load(“newuser.xml”);

      What I think is the best overall method is to use PHP to generate 2 XML files. One for you as the master XML list that will be appended and one for Flash that will overwrite or be overwritten per user. In this way Flash will display only the one new XML data entry per user. Of course you can do the whole thing in Flash too.

      Hope that helps.
      Thanks,
      Ed

      • Dale says:

        Thank you Ed,
        I really appreciate you taking the time to walk me through this.

        As I explore my options (with & w/o YSB) I’ll venture back to AITpro with an update.

        Thanks again
        Dale


Skip to toolbar