views:

39

answers:

1

Can i do the following in actionscript-3? :
I want to make an application that loads some images with a Loader by making URLRequests to a local folder. Can i build the application and include somehow this folder so when i send it from a server to a client the URLRequests operate normally on clients side? Also if this is possible, the folder may be not viewable/accessible by the client but only from the Flash application that comes with it? So for example, this piece of code that runs nicely, locally, to my machine, if i send it to a client will continue to run to its machine. Can somehow send the folder and the SWF as one object?

private function clothesOn( outfit:String ) {
   var clothier:Loader = new Loader();
   var item:String = "clothes/" + outfit + ".gif";
   var getItem:URLRequest = new URLRequest( item );
   clothier.load( getItem );
   this.addChild( clothier );
}

ps:code taken from actionscript design patterns.

+1  A: 

There's no way to send files to the client unless they're added as library assets in the flash file itself. However, if the folder is on your server in the same relative location as it is on your local machine, and you instruct the flash file to make all paths relative to itself (using the base:'.' param) then the flash file should be able to find your image files without needing to send them to the client first.

The base param is a value you can specify when embedding your flash file in your page. See here:

http://kb2.adobe.com/cps/127/tn_12701.html

Using SWFObject, the code would look something like this:

<script type="text/javascript">
    var params = {
        menu: "false",
        scale: "noScale",
        allowFullscreen: "true",
        allowScriptAccess: "always",
        bgcolor: "#FFFFFF",
        base:'.'
    };
    swfobject.embedSWF("file.swf", "divID", "706", "706", "9.0.0", "swf/expressInstall.swf", null, params, null);
</script>

Once that param is set, urls within your flash file will be relative to the location of the file itself. So assuming you have a structure like this on your server:

-root
  -index.html
  -file.swf
  -folder
    -img1.jpg
    -img2.jpg

a url like 'folder/img1.jpg' will be loaded by the flash file just fine.

DHuntrods
Can you please expand a little your suggestion? What is the base: param you say?
Ponty
I've expanded on the answer above. I hope it helps!
DHuntrods
So what you say is that I can make a folder on the server and declare its path via swfobject ( can be declared from actionscript inside? ) and then every time i use the URLRequest as in my first example then the corresponding file will be downloaded in the client's side(?), or the jpeg files are being found by the flash application when i build it thus they do not downloaded at runtime(?).Please make this clearer.
Ponty
DHuntrods
ok thanks for making it clear to me! also this property can be declared from actionscript inside like with an Embed metadata command or something similar?
Ponty
Glad to help =) Not that I'm aware of- as far as I know it's solely for when you're embedded the flash in the html so is set only through the html.
DHuntrods