dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: SWF Studio Commands for Opening External File

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    12

    SWF Studio Commands for Opening External File

    Hello,

    I am trying to open an external file (.pdf .xls .ppt) from a projector using SWF Studio v3.4.

    I have read about opening using a .bat, .exe and .txt combination - but I hear that I can do it directly from the Projector (made with SWF Studio) without the need of these extras.

    So to be specific, what EXACT code should I add on the button release function in order to achieve this.

    Thanks in advance.

    K.

  2. #2
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    If the file you want to open is in the same folder as your EXE then this is what you want to put in your buttin release function. The same code will work for PDF, XLS, PPT or any other file type, just change the file name for your other buttons and you're done.

    Code:
    ssCore.Shell.open({path:"startdir://myfile.pdf", verb:"open"});

  3. #3
    Junior Member
    Join Date
    Jan 2008
    Posts
    12
    Tim,

    So should the exact code read as follows:

    on (release) {
    ssCore.Shell.open({path:"startdir://myfile.pdf", verb:"open"});
    }

    Because when I export from Flash, I get an error about the statement having to appear within an 'on handler'.

    Regards,

    K.

  4. #4
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    If you try and put that code in a frame on the timeline that's the error you'll get. If you think about it, Flash has no way to tell which button you wanted that code attached to.

    If you click on the button first and then press F9 (to open the ActionScript editor window) you will be adding the code in a "handler" and then it will compile properly and work.

    Alternatively, if you've given the button instance a name (like button1, then you can add the code to the button like this (below), and that code should go into a frame on the timeline.

    Code:
    button1.onRelease = function() 
    {
       ssCore.Shell.open({path:"startdir://myfile.pdf", verb:"open"});
    }

  5. #5
    Junior Member
    Join Date
    Jan 2008
    Posts
    12
    Tim,

    Thanks for the quick reply - I just tested things out and lo' n behold - IT WORKED! - well I guess you knew that, right!

    Thanks.

    How is that SWF Studio tutorial comng along? I sure could use one in addition to this (forum) invaluable resource.

    K.

  6. #6
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    Actually, perfect timing... I just set up a new XP demo machine last night. I have to finish installing the various flavors of Flash and then we can start building some nice tutorial videos.

  7. #7
    Junior Member
    Join Date
    Jan 2008
    Posts
    12
    Will definately be on the lookout for that - a must have.

    The other thing, I'm making a cd which features video footage. How do I go about having the video open up in Windows Media Player when someone clicks on the video, i.e. WMP "within" the projector.

    Regards,

    K.

  8. #8
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    Exactly the same code will work for opening video files as for PDF files. The Shell.open command is like double clicking on a file. You just tell it what file you want to open and SWF Studio does the rest.

    You can play video files with the WMVideo commands, check out this example to see WMVideo in action. This is a little more fancy because it embeds an instance of the Windows Media Player in your application so it looks like part of your interface. You can track playback events and control the size and position. Full source and SWF Studio project files are included in the example.

  9. #9
    Junior Member
    Join Date
    Jan 2008
    Posts
    12

    Northcode

    Using the code you provided I managed to open files that were in the main folder. How about when files are in sub-folders?

    I've tried adding forward and backslashes on the code but to no avail - help me out.

    Regards,

    G.

  10. #10
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    If a file is in a folder called "thefiles" adjacent to your EXE, then this is the command you would use.

    ssCore.Shell.open({path:"startdir://thefiles\\myfile.pdf", verb:"open"});

    SWF Studio will add the path separator for you automatically between startdir:// and the first component of the path. You need to supply any additional separators between other folder and file names.

    A path separator on Windows is a backslash \. When you want to put a backslash in quotes in ActionScript code you need to escape it. So instead of just adding \ you have to put \\ in the quoted string.

    The String Literals vs. String Values post on my blog explains the grubby details about backslashes and strings in ActionScript if you need a deeper explanation.

  11. #11
    this code:
    ssCore.Shell.open({path:"startdir://thefiles\\myfile.pdf", verb:"open"});
    ...has helped a TON.

    What if the "thefiles" folder was dragged into the 'Layout' folder in the Files tab?
    How would you call myfile.pdf then?

  12. #12
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    If the files were marked as "AutoExtract" in the layout (so they get extracted to an internal temp folder when your app starts) then you just have to change the moniker from startdir:// to internal:// or tempdir://. These monikers both point to the root folder where files are autoextracted from the layout.

    ssCore.Shell.open({path:"internal://thefiles\\myfile.pdf", verb:"open"});

    SWF Studio will recreate the folder structures that you create in the Files tab when it extracts the files.

  13. #13
    Junior Member
    Join Date
    Jan 2008
    Posts
    12
    Tim,

    Having bundled my app. in one .exe file and selected 'AutoExtract' - is there any way to show 'Loading..' and a percentage when the app. is started and it's autoextracting. My app takes about 3-4 minutes to fully extract - and though i know that I could use an image - I would like to be able to show how much has been extracted - so the user can see that there is activity.

    Thanks in advance.

    G.

    PS: Howz that video tutorial coming along?

  14. #14
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    The AutoExtract files are pulled out of your EXE before your code runs so there's nothing you can do at that point.

    What you can do is NOT mark them as AutoExtract and extract them yourself using ssCore.Layout.getFileList and ssCore.Layout.extractFile. That way you can show a progress bar in Flash as you pull the files out.

    Tutorials will start appearing very shortly after the release of V3.5

  15. #15
    Junior Member
    Join Date
    Jan 2008
    Posts
    12
    Northcode,

    Any reason why an application wouldn't run on a machine...

    Since first posting I've been making applications on cd-rom, however on some machines the applications fail to run - while on others they run fine. Any idea why this would be so?

    Regards,

    Galamukani.

  16. #16
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    If the user doesn't have the application requried to open the file it will fail. If the CD doesn't spin up fast enough, the app you're using might not be able to find the file and give up. Those would be my first guesses. Do you have access to a machine you can reproduce this on?

  17. #17
    Junior Member
    Join Date
    Jan 2008
    Posts
    12
    What I meant was when you insert the cd in the drive, the app. autoruns fine - but then when you try and click any button on the interface the whole app just closes up i.e. "dissappears"!

    I hope you understand what I'm trying to explain...

  18. #18
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    Are you still using V3.4? We've actually released V3.5 and it's even more stable than V3.4 (and has support for AS3, Flash CS3 and Flex now). You shouldn't have to do anything but rebuild your EXE with the new version.

  19. #19
    Junior Member
    Join Date
    Sep 2008
    Posts
    4

    can this approach be used to load swf from file within exe?

    I want to include a swf within the .exe and add it as a child to my swf at runtime, so it doesn't have to appear/be within the folder that contains the projector. I.e. not "external". I've tried just adding it to the layout folder under the "files" tab, using the normal loader/url construction:

    "var request:URLRequest = new URLRequest("filename.swf");
    var loader:Loader = new Loader();

    loader.load(request);
    this.addChild(loader);"

    but that didn't work, SO I found this thread and thought I'd try:

    var request:URLRequest = new URLRequest(ssCore.Shell.open({path:"internal:filen ame.swf", verb:"open"}));
    var loader:Loader = new Loader();

    loader.load(request);
    this.addChild(loader);

    But I got an error when compiling the "primary" swf- "1120:Access of undefined property ssCore" and when running the exe, it just ran the "primary" swf and didn't load the target swf.

    The call is being made from frame 2 of the "primary" swf timeline, and the normal syntax works fine when the target swf is just a swf in the same folder as the exe. But what I'm looking to do is "hide" the target swf within the exe.

    Can do? How?

  20. #20
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    We added ssURLLoader to V3.5 to replace the old ssSecure class for ActionScript 3 projects.

    ssURLLoader is used the same way as URLLoader, except the paths are relative to the SWF Studio layout, which is exactly what you want!

    Files are streamed in from the layout directly into the Flash Player without first being extracted to the hard drive. ssURLLoader does not use an HTTP server like ssSecure so will not trigger firewalls.

    Code:
    The following example assumes there is a file in the layout called loadme.swf:
    
    package
    {
    	import flash.display.Sprite;
    	import flash.net.URLRequest;
    	import flash.display.Loader;
    	import flash.events.Event;
    	import flash.net.URLLoaderDataFormat;
    	import flash.net.URLLoader;
    
    	public class ssURLLoaderTest extends Sprite
    	{
    		public var req:URLRequest;
    		public var ldr:Loader;
    		public var uldr:*;
    		
    		public function ssURLLoaderTest()
    		{
    			addEventListener(Event.ADDED_TO_STAGE, onAdded, false, 0, true);
    		}
    		
    		public function onAdded(e:Event):void
    		{
    			removeEventListener(e.type, arguments.callee);
    
    			ldr = new Loader();
    			req = new URLRequest();
    		
    			if (ssCore.isEXE) 
    				uldr = new ssURLLoader();
    			else 
    				uldr = new URLLoader();
    			
    			uldr.addEventListener(Event.COMPLETE, onComplete);
    			uldr.addEventListener(ProgressEvent.PROGRESS, onProgress);
    			uldr.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
    		
    			req.url = 'loadme.swf';
    
    			if (ssCore.isEXE) 
    				uldr.bufferSize = '8192';
    
    			uldr.dataFormat = URLLoaderDataFormat.BINARY;
    			uldr.load(req);
    		}
    		
    		public function onProgress(e:ProgressEvent):void
    		{
    			ssDebug.trace('onProgress: '+e.bytesLoaded+' of '+e.bytesTotal);
    		}
    		
    		public function onIOError(e:IOErrorEvent):void
    		{
    			ssDebug.trace('onIOError: '+e.text);
    		}
    		
    		public function onComplete(e:Event):void
    		{
    			ssDebug.trace('onComplete');
    			ldr.loadBytes(uldr.data);
    			addChild(ldr);
    		}
    	}
    }

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