Tagged: actionscript

New file in Mac OS X Finder

- by admin

Sometimes we need to create a file from Finder directly. And this is strange that Finder allows easily to create a folder but not a file! Although Linux and Windows file browsers have this option. So, let's enhance Finder!

First start Automator (Launchpad / Other / Automator). In the chooser that appears next, select Service.



At the top of the Automator main window, set the "Service Receives Selected" drop-down to "files or folders". Then select Library / Utilities in the left tree menu. Next drag (or just double click) "Run AppleScript" into the main working area (mid-right). Here you will get "Run AppleScript" box. Paste the following AppleScript into this code box, then click the hammer icon to compile the code:
on run {input, parameters}
tell application "Finder"
set currentPath to insertion location as text
set x to POSIX path of currentPath
end tell
return x
end run

Next double click on "Set Value of a Variable" (also in the LIbrary / Utilities section). Click the "Variable" drop-down and create a new variable. Let's call it currentFolder.

Select Library / Text in the left tree menu. Next drag (or just double click) "New Text File" into the main working area (mid-right). Here you will get "New Text File" box.

Drag the variable you just created (currentFolder) from the Variable panel at the bottom of the Automator window to the "Where" selector of the "New Text File" action. Change "Encoding" to "Unicode (UTF-8)". Click the New Text File's "Options" button (at the bottom of the box) and select "Show this action when the workflow runs". This will allow you to specify the names of new files.



Save the service with "File / Save ..." top menu and give it a name (For example "New File"). To test it, in the Finder go to the folder where you want to create a new file. Control-click on an existing file within that folder and select "New File" from the "Services" submenu. A dialog should appear requesting a filename. Enter one then click "Continue"; your new file should appear.



This obviously creates a text or RTF empty file (file with .txt or .rtf extension). You can change the extension to whatever you need as the last step.

Decrypting XML File with Actionscript 2.0, memory problem?

- by admin

Q:

I have an encrypted XML file that needs to be decrypted and displayed in Flash. The Encrypted XML file contains over 33000 characters, Flash crashes when I try to decrypt it. Is there a limit to amount of data that Flash can decrypt? I'm using rijndael to decrypt and Actionscript 2.0.


Just that the script is causing the flash player to run slowly and if it continues to run, my computer may become unresponsive. It then asks me do I want to abort. If I don't, it just keeps reappearing. the only code in the file is to decrypt, so it isn't caused by anything else.

A:




Your problem is caused by the non-existing multithreading capabilities in Flash: All calculations are supposed to happen "in-between frames", i.e. user algorithms should not take longer to execute than the interval at which the screen is refreshed. If your calculation takes too long to finish, the Flash player will first start to drop frames, and (unless you changed settings) after 15 seconds show the warning you described.


You can get around this by "spreading" your algorithm across multiple frames, making sure only part of the calculation is executed until the screen is refreshed. You can do so by simply splitting up your encrypted string into small enough parts and executing an enterFrame loop to decrypt one at a time, or by implementing something like Alex Harui's PseudoThread class (which essentially does the same, but comes with encapsulation and all that Jazz).





« All tags