Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Participant ,
Oct 17, 2024 Oct 17, 2024

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.

 

 

 

 

551
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2024 Oct 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 18, 2024 Oct 18, 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:)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 18, 2024 Oct 18, 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.

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2024 Oct 19, 2024

Forgot to mention that this is an AIR for desktop application.

image.png

 

If you don't have AIR in your system, download the latest version from Harman and then add the root folder of the downloaded SDK to Animate by going to Help > Manage Adobe AIR SDK....
image.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 19, 2024 Oct 19, 2024

i know air has some quirks too, like for instance  the embed command supposedly allows you to just pick a symbol right OUT of a swf,  not sure what method im going to do image loading with .

 

also noticing somedthing strange i know what it IS per say now, but not gettting why they did it.

 

i also tried running the item off the github and got e even stranger error. it says to run "primitives.fla(goes fine) but when i do the example.fla one, i get an error about a currupted swf that i have to 3 finger solute animate cc as it comes up with "live preview errror on a swf" and its a loop that i can't break.

 

 

terryw30405050_0-1729355107047.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 30, 2024 Oct 30, 2024
LATEST

i found a simpler solutuon but i'm not sure of one element to make it work, how to i make the swf keep going when it hits a "symbol not found"  error(i will be purposely creating them trying this) . I already know the data i'm looking at and the data i'm NOT going to get.  next step to try is to load an array with all the possibilites that i'm looking for in a switch/case setup. for instnace i'm looking for  all files that are "green" xmas trees and the files could be red, yellow or blue or multicolor.but  they all have the same basic elements so i don't have to sort EVERY symbol out, just 1. every other element in that file will also be for a green tree.

my solution was so far was all teh trees are known to have  the same structure "Tree_body_*color" as an example.  set the sorting list to try to load each color when it fails, until it hits one that does or gets to a end statement "This is not a tree" for instnace . its not fast, but its automated and honestly sitting around watching netflix is a lot better than babysitting a process or doing it by hand.  lets say theis 500 files to sort, s000 to s499.swf that can be done by I and a if/then loop.  i estimate one file would take 5-6 seconds to search all possibities and thats a pretty huge time savings if you think about it. eyeball savings too opening them all ...les not think about that one(done it before).

 

 

if i felt really fancy i could even push them into a array and then output it which would be kinda neat to see.

 

"when i =499 trace "yellow tree files, then green  etc " and if its working as i got the loader going,. drop that list into the dropdowns for the user to make use of the files as they wish. making such a tool is handy as for the game i'm trying to restore, their is a distinct chance i could have upto 14.000 swfs dropped on me having the tool and well, even if it has to run in batches to process, its far less annoying to debate how big i of the loop needs to be before the risk of crashing animate cc is than manually sorting them.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines