Skip to main content
Inspiring
October 17, 2024
Question

how to load a pile of swfs one at a time in a loop and use a switch/case script to sort them.

  • October 17, 2024
  • 1 reply
  • 598 views

this one is not coming up in any of my actionscript books so far and wondering if anyone has done this before.

 

what im trying ot do is have teh following happen :

 

write a loop that does the following

 

1. opens a swf named from d000 to d750.swf (yes theirs that many)

 

2. pulls a list of the symbols and returns one  of them to switch/case search

3. run said list through a switch and case filter and pushes the results to the output console

4. goes to the next file and repeats this until all the files are processed.

the results i'm looking for would look like this

 

 

ittem 0: s000 : this is a shirt

item 1:  s001 : this is a <not mathcuing any of the above>

item: s003 this is a pair of pants

item s004: this is a pair of glasses

item s005: this is a dress

 

 

 

how does it know this, the switch script will be looking for "pants", "shirt" and send to the output what it is.

 

i need this list to allow my reverse string generator (i select pants on the player screen and it gives a list of pants to choose from,etc) to know what files are and looking at thousnads of files are not very efficent.

 

 

the part im not finding the info is how do i get the list of symbols IN a swf if their not set to the stage by addchild, i've seen things that dump the displaylist, but its also not one item tyopically that a switch search can handle.

 

 

 

 

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    October 18, 2024

    Hi.

     

    Extracting the symbols from a SWF is a little bit involved as it requires low level development. Fortunately there are a few libs around that seem to be able to do this, like https://github.com/Flassari/Swf-Class-Explorer, from Flassari.

    So I did a little AIR for desktop app that is able to navigate for a folder containing SWFs and listing their symbols using the lib above.

    Not sure if it's what you want, but I hope it at least helps you to get started.

    AS3 code:

     

    import com.flassari.swfclassexplorer.SwfClassExplorer;
    
    import flash.display.Loader;
    import flash.display.LoaderInfo;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.MouseEvent;
    import flash.events.SecurityErrorEvent;
    import flash.filesystem.File;
    import flash.filesystem.FileMode;
    import flash.filesystem.FileStream;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    import flash.system.System;
    import flash.utils.ByteArray;
    
    var descriptions:Object =
    {
    	"BlueSquare": "This is a blue square",
    	"GreenSquare": "This is a green square",
    	"LightBlueSquare": "This is a light blue square",
    	"RedSquare": "This is a red square",
    	"YellowSquare": "This is a yellow square"
    };
    
    function main()
    {	
    	browseButton.addEventListener(MouseEvent.CLICK, onBrowseHandler);
    	clearButton.addEventListener(MouseEvent.CLICK, onClearHandler);
    	copyButton.addEventListener(MouseEvent.CLICK, onCopyHandler);
    	saveAsButton.addEventListener(MouseEvent.CLICK, onSaveAsHandler);
    }
    
    function onBrowseHandler(e:MouseEvent):void
    {
    	browse();
    }
    
    function onClearHandler(e:MouseEvent):void
    {
    	listTF.text = "";
    }
    
    function onCopyHandler(e:MouseEvent):void
    {
    	System.setClipboard(listTF.text);
    }
    
    function onSaveAsHandler(e:MouseEvent):void
    {
    	if (listTF.text == "")
    		return;
    		
    	var desktopDirectory:File = File.desktopDirectory.resolvePath("swf_list_" + new Date().time + ".txt");
    	
    	try
    	{
    		desktopDirectory.browseForSave("Save As");
    		desktopDirectory.addEventListener(Event.SELECT, onSaveSelected);
    	}
    	catch (error:Error)
    	{
    		trace("Failed:\n", error.message);
    	}
    }
    
    function onSaveSelected(e:Event):void
    {
    	var newFile:File = e.target as File;
    	var stream:FileStream = new FileStream();
    	
    	stream.open(newFile, FileMode.WRITE);
    	stream.writeUTFBytes(listTF.text);
    	stream.close();
    }
    
    function browse() 
    {
    	var directory:File = new File();
    	
    	try
    	{
    		directory.browseForDirectory("Select the folder containing the SWF files.");
    		directory.addEventListener(Event.SELECT, fileSelectHandler);
    	}
    	catch (error:Error)
    	{
    		trace("Failed:\n", error.message);
    	}
    }
    
    function fileSelectHandler(e:Event):void
    {
    	var files:Array;
    	var directory:File = e.target as File;
    	var file:File;
    	var i:uint;
    	
    	files = directory.getDirectoryListing();
    	
    	for (i = 0; i < files.length; i++)
    	{
    		file = files[i];
    		
    		if (file.extension == "swf")
    			loadSwf(file);
    	}
    }
    
    function loadSwf(file:File):void
    {
    	var urlLoader:URLLoader = new URLLoader();
    	
    	urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
    	urlLoader.addEventListener(Event.COMPLETE, swfLoadedHandler(file.name));
    	urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    	urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
    	
    	try
    	{
    		urlLoader.load(new URLRequest(file.url));
    	}
    	catch (e:Error)
    	{
    		trace("Error:\n" + e.toString());
    	}
    }
    
    function swfLoadedHandler(fileName:String):Function
    {
    	return function(e:Event):void
    	{
    		var loader:Loader = new Loader();
    		var loaderContext: LoaderContext = new LoaderContext();
    		var bytes:ByteArray = ByteArray(URLLoader(e.currentTarget).data);
    		
    		loaderContext.allowLoadBytesCodeExecution = true;			
    		loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler(bytes, fileName));
    		loader.loadBytes(bytes, loaderContext);
    		
    		e.currentTarget.removeEventListener(e.type, arguments.callee);
    	};
    }
    
    
    function loaderCompleteHandler(bytes:ByteArray, fileName:String):Function
    {	
    	return function (e:Event):void
    	{
    		var symbols:Array = SwfClassExplorer.getClassNames(bytes);
    		var symbolName:String;
    		var description:String;
    		var i:uint;
    		var prefix:String;
    		var line:String;
    				
    		for (i = 0; i < symbols.length; i++)
    		{
    			symbolName = symbols[i];
    			description = descriptions[symbolName];
    			prefix = fileName + " - " + symbolName + ": ";
    			line = prefix + (description || "<description not found>");
    			
    			trace(line);
    			
    			if (listTF.text == "")
    				listTF.text = "\n";
    			
    			listTF.appendText(line + "\n");
    		}
    
    		trace("\n");
    		listTF.appendText("\n");
    	
    		e.currentTarget.removeEventListener(e.type, arguments.callee);
    	
    		LoaderInfo(e.target).loader.unloadAndStop(true);
    	};
    }
    
    function securityErrorHandler(e:SecurityErrorEvent):void
    {
    	trace("A security error occurred:\n" + e.text);
    }
    
    function ioErrorHandler(e:IOErrorEvent):void
    {
    	trace("An IO error occurred:\n" + e.text);
    }
    
    main();

     


    Download / source / FLA / files:
    https://bit.ly/3A22dpQ

    Regards,

    JC

    Inspiring
    October 19, 2024

    this is all i actually what i need to have happen as once i know its a shirt, i can just put them on a array and let that string generator handle it from there. if a dress, it goes to the dress list, etc. thats why i figures i'd need these as a pair of tools since i sorted the last list of swfs by hand and it was a 2 mb list and took me a good week or two in jpexs , see it was a ..... i recall this game making 200 items a month and running for six years. I'm hoping a lot of these concepts work with the html5 canvas when i get done as many of the books and etc i got were mega cheap( often paying more to ship many than paying for them). and its nice to have a library of solutions and i haven't come across too many on doing mmo style games for html5.  The ones i've come across were not this detailed to use as guides, "choose a blue puzzle piece, a red puzzle piece, etc" not this horrifying nightmare of swf assembly. the games were like connect 4, a few other common "not a tetris game" examples etc. that was a interesting read when a judge had to define what could be legally protected as tetris though. good times when they come up in programming books too:)

    Inspiring
    October 19, 2024

    comes back with one error when trying to run it : Scene 1, Layer 'Layer_1', Frame 2, Line 112, Column 23 1046: Type was not found or was not a compile-time constant: File.