Thursday, January 5th, 2006

Category: FlashCategory: SWF Studio

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.

MovieClip.prototype._draggable
Availability:

3.0 build 2039

Usage:

MovieClip._draggable = Boolean

Returns:

Boolean.

Description:

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.

Example:
myMovieClip._draggable = true;
Object.protoype.copy
Availability:

3.0 build 2039

Usage:

Object.copy()

Parameters:

None.

Returns:

Object.

Description:

Method; use to make a copy of an object, not just a reference.

Example:
var originalObj = new Object();
originalObj.param1 = 'some text';
originalObj.param2 = 'blah';

var newObj = originalObj.copy();

ssDebug.trace(newObj.param1); // outputs: 'some text'
Object.protoype.copyTo
Availability:

3.0 build 2039

Usage:

Object.copyTo(receivingObject)

Parameters:

receivingObject - Object - The object to which the members of the original object are copied.

Returns:

Object.

Description:

Method; use to copy members of an object to an existing object.

Example:
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'
Object.protoype.isArray
Availability:

3.0 build 2039

Usage:

Object.isArray()

Parameters:

None.

Returns:

Boolean.

Description:

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.

Example:
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
Array.prototype.copy
Availability:

3.0 build 2039

Usage:

Array.copy()

Parameters:

None.

Returns:

Array.

Description:

Method; use to make a copy of an array, not just a reference.

Example:
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'
String.prototype.parentPath
Availability:

3.0 build 2039

Usage:

String.parentPath([delimiter])

Parameters:

delimiter - String - Optional - Use to specify the delimiter in the path. The default is a backslash \.

Returns:

String.

Description:

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.

Example 1:
var pathToSWF = 'C:\\Folder\\file.swf';
var folderSWFIsIn = pathToSWF.parentPath();
ssDebug.trace(folderSWFIsIn); // outputs: 'C:\\Folder'
Example 2:
var pathToFolder = 'C:\\Folder\\Child Folder';
var parentFolderPath = pathToFolder.parentPath();
ssDebug.trace(parentFolderPath); // outputs: 'C:\\Folder'
Example 3:
var pathToFolder = 'C:\\Folder\\Child Folder\\';
var parentFolderPath = pathToFolder.parentPath();
ssDebug.trace(parentFolderPath); // outputs: 'C:\\Folder\\Child Folder'
Example 4:
var pathToSWF = '/Folder/file.swf';
var folderSWFIsIn = pathToSWF.parentFolder('/');
ssDebug.trace(folderSWFIsIn); // outputs: '/Folder'
String.prototype.parentFolder
Availability:

3.0 build 2039

Usage:

String.parentFolder([delimiter])

Parameters:

delimiter - String - Optional - Use to specify the delimiter in the path. The default is a backslash \.

Returns:

String.

Description:

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).

Example 1:
var pathToSWF = 'C:\\Folder\\file.swf';
var folderSWFIsIn = pathToSWF.parentFolder();
ssDebug.trace(folderSWFIsIn); // outputs: 'Folder'
Example 2:
var pathToFolder = 'C:\\Folder\\Child Folder';
var parentFolderName = pathToFolder.parentFolder();
ssDebug.trace(parentFolderName); // outputs: 'Folder'
Example 3:
var pathToFolder = 'C:\\Folder\\Child Folder\\';
var parentFolderName = pathToFolder.parentFolder();
ssDebug.trace(parentFolderName); // outputs: 'Child Folder'
Example 4:
var pathToSWF = '/Folder/file.swf';
var folderSWFIsIn = pathToSWF.parentFolder('/');
ssDebug.trace(folderSWFIsIn); // outputs: 'Folder'
String.prototype.relativePath
Availability:

3.0 build 2039

Usage:

String.relativePath(dotDotSlash [, delimiter])

Parameters:

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 \.

Returns:

String.

Description:

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.

Example:
// 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.

One Response to 'Undocumented tidbits in SWF Studio 3'

Subscribe to comments with RSS or TrackBack to 'Undocumented tidbits in SWF Studio 3'.

  1. André Goliath | Friday, January 6th, 2006 | 11:24 am

    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?

Leave a Reply

If this is your first comment it will need to be approved before it will appear.