Leticia Meyer
Leticia Meyer

Reputation: 217

Resize, move, export coordinates of objects in flash

How would I place objects in flash, moving and resizing them, etc. and then export coordinates/rotation to a text file or something like that?

Upvotes: 0

Views: 1189

Answers (1)

George Profenza
George Profenza

Reputation: 51847

Do you mean at runtime or at author time(in the IDE) ?

For runtime, you would just loop through the clips you're interested and store the properties in a text/xml:

var layout = <layout />;//create the root node for our xml
var elementsNum = numChildren;//store this for counting

for(var i = 0 ; i < elementsNum ; i++){
    var clip = getChildAt(i);
    layout.appendChild(<element />);//add an element node
    layout.element[i].@name = clip.name;//setup attributes
    layout.element[i].@x = clip.x;
    layout.element[i].@y = clip.y;
    layout.element[i].@rotation = clip.rotation;
    layout.element[i].@scaleX = clip.scaleX;
    layout.element[i].@scaleY = clip.scaleY;
}

flash.system.System.setClipboard(layout);
trace('layout copied to clipboard');

This would create an xml where each clip in the current MovieClip is a node and some properties are stored. The xml is then copied to the clipboard.

You could do something similar at author time with something simple, like the selection:

var doc = fl.getDocumentDOM();//get the current document ref.
var selection = doc.selection;//get the selection
var layout = <layout />;//create the root node for our xml
var elementsNum = selection.length;//store this for counting

for(var i = 0 ; i < elementsNum ; i++){
    layout.appendChild(<element />);//add an element node
    layout.element[i].@name = selection[i].name;//setup attributes
    layout.element[i].@x = selection[i].x;
    layout.element[i].@y = selection[i].y;
    layout.element[i].@rotation = selection[i].rotation;
    layout.element[i].@scaleX = selection[i].scaleX;
    layout.element[i].@scaleY = selection[i].scaleY;
}

var url = fl.browseForFileURL('save','Save Layout');//prompt for location
if(url) fl.trace(FLfile.write(url,layout));//save

If you save this as a .jsfl file in the Flash's Commands folder it should pop up in the Commands menu in the IDE, otherwise you should be able to simply run it. Not that it stores the name property, so the selection should contain MovieClip(or elements with name). Then the save dialog is displayed and the xml is saved to a text file.

These are basic examples, but should allow you to get started and write this text file the way you need it (You might want to traverse all the movie clips instead of the selection, might want to store different properties, etc.)

Shameless plug: you might find this slim JSFL presentation handy.

HTH

Upvotes: 1

Related Questions