I'm building a Flash project that will read a folder to get the names of pictures & videos so they can be added dynamically to the Flash project. The .swf, .app or .exe, however I output the final version, will run on a PC or Mac that's hooked up to a large flat screen monitor.
If the project was being used on the web I'd just call a .php script to dump the file names into an .xml file. However, the Flash & computer will be offline.
I'm haven't built anything with AIR so I don't have enough time to get up to speed with it in order to use it. I know AIR's AS3 has a FileListEvent class that has the getDirectoryListingAsync method to read a directory.
So my question is, is there a way to read the names of a directory from a folder when the Flash is running offline?
I was wondering if running a DOS script or a Mac DOS-like script would be do-able.
Or is there a better way?
Thanks in advance for your reply,
You can't do it with Flash alone, and trying to get some OS script to work on both mac and PC is going to be problematic at best. You're going to just need to bite the bullet and use AIR, it's not that hard... Here's an example to get you going:
Your options are a bit limited. Flash has absolutely no access to reading the filesystem beyond you explicitly telling it what file to read. There's more to using AIR than just trying to use its libraries so if time is of the essence that won't help you.
You can manage an XML file yourself as you said you'd have a PHP script generate. It might be that "it will just had to do" answer.
You can set up a self installable XAMPP server and use PHP as you mentioned, offline.
If you can spend some money then I highly recommend MDM Zinc. It is a projector extender that gives you many abilities in an AIR-like way and you can even write plugins for it if the built-in library doesn't have what you need. I use it quite often. I also have Screentime's mProjector which is similar but I find Zinc to be far more updated and feature full.
I think the local webserver is probably your best option. It's free, easy and familiar.
>>I think the local webserver is probably your best option. It's free, easy and familiar.
Using AIR's file classes would be MUCH quicker and easier. And using AIR is hardly any different than using Flash alone... you just get more, and it's free too...
And also, wrappers like Zinc, SWFKit, etc. were pretty handy, but I've not needed any wrapper like that for quite a long time, AIR does pretty much everything they do without any additional cost.
Ah, you're probably right. I find AIR projectors aren't as simple to get running fullscreen as there's a bunch of chrome options to adjust as well as SWF metadata that if is incorrect can really make you scratch your head.
As long as you're using something compatible with a decent version of AIR it shouldn't be much trouble. If you already created the project then you'd change it from an ActionScript 3.0 project to an AIR project. Then you'd really want to make sure you overlay the latest version of AIR over your Flash install.
Latest version of AIR:
Overlay AIR instructions (CS5.5+):
Latest version of Flash Player / Debugger / playerglobal.swc:
Here's a quick full example of using AIR to list the files on your desktop, and their filesize. You can just open a new AIR file and paste it in frame 1, watch the trace output:
var dirFiles:File = File.desktopDirectory.resolvePath(File.desktopDirectory.nativePath);
dirFiles.addEventListener(FileListEvent.DIRECTORY_LISTING, dirListComplete, false, 0, true);
var files:Array = e.files as Array;
for (var fileIndex:int = 0; fileIndex < files.length; fileIndex++)
trace("Filename: " + files[fileIndex].name + " [" + files[fileIndex].size + " bytes]");
Each file has many properties you can read (name and size used above). Check the docs for all the available file info in the File class:
Thanks for the suggestions sinious,
I'll look into converting the flash into an AIR project so I can use the file Class.
Depending on my time contraints, it's a rush job, I might have to install the XAMPP server and run the .php script offline.
AIR isn't a bad option if you're using Flash Pro CS5.5+ already and don't mind updating the libraries and app. Be sure the target machine also has the latest AIR installed as well (I think CS6 allows captive runtime otherwise).
I merely recommended XAMPP because you mentioned you'd just do it with a PHP script on the web so I recommended that based on familiarity.
You don't need to use all those options in the publish dialog to get AIR to go fullscreen. I never touch any of those... All I do for fullscreen with hidden mouse is this:
stage.displayState = StageDisplayState.FULL_SCREEN;
stage.scaleMode = StageScaleMode.EXACT_FIT;
I make more kiosks than just about anything else of late. I find running EXACT_FIT takes a slight performance hit over NO_SCALE. It doesn't make sense because theoretically the resolution is the same if the resolution and project are the same (always running on 40"+ touchscreens at 1920x1080, document at 1920x1080).
Another good setting to consider if this is a kiosk is:
stage.nativeWindow.alwaysInFront = true;
Depends on your environment. I've had some kiosks that allow mouse control with a real keyboard so the user can type in things much easier (search store products, etc). Then it becomes really important to control what is visible. Simply setting alwaysInFront will keep the kiosk above all other applications at all times.
Sometimes a client wants an app that can act like a toolbar and if it needs to be on top at all times (in a helpful way) then this is useful. A random old project that utilizes it I happen to have a screenshot of for example:
The whole gray bar across the top and panel on the right is Flash. It's a CAD tutorial for a product to help users learn how to get up to speed quickly. We worked with Razor Scooter to make something fun.
I always hated tutorials so I wanted to make something that was out of the way but visible at all times. It also pops a video panel to show each step of the tutorial being done by a pro to make it really easy. alwaysOnTop makes things like that possible.
I've done several other training products in the very same way, overlaying applications.
a co-worker of mine told me that apache & .php are built into Mac OS X. there's a good chance i'll be running the flash on a Mac so I can take advantage of this option.
Yes I can definitely confirm they come pre-installed. I have OSX Lion next to me at all times incase I need to make a simple .p12 and it's on there.
Glad you found a simple built in solution and if you're done can you please mark the thread answered so we can filter unanswered questions. Good luck!