Thursday, January 5th, 2006 |
|
Undocumented tidbits in SWF Studio 3 |
There are some undocumented actionscript goodies that come with the SWF Studio 3 ActionScript API that I thought I’d share. There are only a few, but they are ones that Flash should have built-in.
This was not an attempt to cover every bit of code that I felt could be in ActionScript, but a few that are useful for everyday tasks. One is strictly for SWF Studio. The others are more generic.
There are no class files or AS2 definition files for these, but you don’t really need any. You’ll be able to use all of these without an issue except for the String add-ons. The String class in AS2 is not dynamic so you can’t simply refer to a method that doesn’t exist without getting a compiler error.
The solutions are to:
1. include the methods in the String.as file in the MX04/F8 Classes folder,
2. not give a type to the string you are going to use the methods on,
3. assign the string to an untyped temporary variable and issue the methods on that variable.
The cleanest would be the first option, although you’ll run into issues when giving your code to anyone who hasn’t patched their String.as file. So, while clean for your project, it really isn’t a “good” way to handle this.
The second and third options mean you bypass type-checking. The third option is probably the best because you’ll probably only use the methods occasionally anyhow, and type-checking is nice to keep.
3.0 build 2039
MovieClip._draggable = Boolean
Boolean.
Property; SWF Studio-only. Provides a simple method for making your application window draggable. Setting this property to true means that when a user clicks and drags the movieclip they are actually dragging the entire application, not the movieclip.
The mouse events for any movieclips on top of the target movieclip (the one where this property is set to true) will continue to work. When the mouse is over a movieclip/button that has a mouse event (onPress, etc.) the application will not be draggable. This ensures that buttons and other movieclip functionality continue to work even if they are on top of the target movieclip.
Code that performed this functionality was posted in the Northcode forums for SWF Studio V2 as a replacement for drag regions.
Note: If you write an onRollOver and/or onRollOut function for your movieclip, make sure to set this property again.
myMovieClip._draggable = true;
3.0 build 2039
Object.copy()
None.
Object.
Method; use to make a copy of an object, not just a reference.
var originalObj = new Object(); originalObj.param1 = 'some text'; originalObj.param2 = 'blah'; var newObj = originalObj.copy(); ssDebug.trace(newObj.param1); // outputs: 'some text'
3.0 build 2039
Object.copyTo(receivingObject)
receivingObject - Object - The object to which the members of the original object are copied.
Object.
Method; use to copy members of an object to an existing object.
var myObj = new Object(); myObj.param1 = 'something'; var originalObj = new Object(); originalObj.param1 = 'some text'; originalObj.param2 = 'blah'; myObj.copyTo(originalObj); ssDebug.trace(originalObj.param1); // outputs: 'something'
3.0 build 2039
Object.isArray()
None.
Boolean.
Method; provides a simple way to test an unknown object to see if it’s an Array rather than a generic object. The typeof Flash method will return ‘object’ for generic objects and arrays.
var myObj = new Object(); ssDebug.trace(typeof(myObj)); // outputs: 'object' ssDebug.trace(myObj.isArray()); // outputs: false var myArr = new Array(); ssDebug.trace(typeof(myArr)); // outputs: 'object' ssDebug.trace(myArr.isArray()); // outputs: true
3.0 build 2039
Array.copy()
None.
Array.
Method; use to make a copy of an array, not just a reference.
var myArr = new Array(); myArr[0] = 'item 0 of myArr'; var newArr = myArr; newArr[0] = 'item 0 of newArr'; ssDebug.trace(myArr[0]); // outputs: 'item 0 of newArr' ssDebug.trace(newArr[0]); // outputs: 'item 0 of newArr' // Instead, use the copy command. var myArr = new Array(); myArr[0] = 'item 0 of myArr'; var newArr = myArr.copy(); newArr[0] = 'item 0 of newArr'; ssDebug.trace(myArr[0]); // outputs: 'item 0 of myArr' ssDebug.trace(newArr[0]); // outputs: 'item 0 of newArr'
3.0 build 2039
String.parentPath([delimiter])
delimiter - String - Optional - Use to specify the delimiter in the path. The default is a backslash \.
String.
Method; returns a string that is the path of the parent folder. If you provide a folder path, without a filename and extension, the parent folder path of the folder specified is returned.
If you are providing a folder path, always specify the path without an ending \ (or specified delimiter) otherwise the returned path will simply be the same folder path without the ending delimiter.
var pathToSWF = 'C:\\Folder\\file.swf'; var folderSWFIsIn = pathToSWF.parentPath(); ssDebug.trace(folderSWFIsIn); // outputs: 'C:\\Folder'
var pathToFolder = 'C:\\Folder\\Child Folder'; var parentFolderPath = pathToFolder.parentPath(); ssDebug.trace(parentFolderPath); // outputs: 'C:\\Folder'
var pathToFolder = 'C:\\Folder\\Child Folder\\'; var parentFolderPath = pathToFolder.parentPath(); ssDebug.trace(parentFolderPath); // outputs: 'C:\\Folder\\Child Folder'
var pathToSWF = '/Folder/file.swf';
var folderSWFIsIn = pathToSWF.parentFolder('/');
ssDebug.trace(folderSWFIsIn); // outputs: '/Folder'
3.0 build 2039
String.parentFolder([delimiter])
delimiter - String - Optional - Use to specify the delimiter in the path. The default is a backslash \.
String.
Method; returns a string that is the name of the parent folder. If you provide a folder path, without a filename and extension, the parent folder name of the folder specified is returned.
If you are providing a folder path, always specify the path without an ending \ (or specified delimiter).
var pathToSWF = 'C:\\Folder\\file.swf'; var folderSWFIsIn = pathToSWF.parentFolder(); ssDebug.trace(folderSWFIsIn); // outputs: 'Folder'
var pathToFolder = 'C:\\Folder\\Child Folder'; var parentFolderName = pathToFolder.parentFolder(); ssDebug.trace(parentFolderName); // outputs: 'Folder'
var pathToFolder = 'C:\\Folder\\Child Folder\\'; var parentFolderName = pathToFolder.parentFolder(); ssDebug.trace(parentFolderName); // outputs: 'Child Folder'
var pathToSWF = '/Folder/file.swf';
var folderSWFIsIn = pathToSWF.parentFolder('/');
ssDebug.trace(folderSWFIsIn); // outputs: 'Folder'
3.0 build 2039
String.relativePath(dotDotSlash [, delimiter])
dotDotSlash - String - Specify the depth of the path to return. The value should consist of any number of “../”.
delimiter - String - Optional - Use to specify the delimiter in the path. The default is a backslash \.
String.
Method; each ../ specified will go back one level in the path provided. This gives an easy way to return a folder path using ../ notation similar to URL paths.
// The SWF in _level0 has a URL of: 'C:\Folder1\Folder2\Folder3\file.swf'
var pathToSWF = _level0._url;
var projectFolderPath = pathToSWF.relativePath('../../');
ssDebug.trace(projectFolderPath); // outputs: 'C:\Folder1\Folder2'
Or view the above as a single HTML page.
Disclaimer
The above information is current as of SWF Studio 3.1 build 86 and is subject to change without notice.
If anything does change, I’ll edit this post to reflect.










Wow!
Thanks for implementing and sharing these very usefull comands!
O boy, if I would have known of these cool object methods,…
No I have to rewrite the SQLite.as class
Well, while you are at it, anything more you want to let us know?
Maybe you want to consider the JScript binary commands Tim exposed a while ago in the Northcode Forums too?