0

I am starting with Adobe Flash CS3(I know it's old but bear with me).

I want to know if it is possible to generate a shape directly in the flv canvas without dragging/dropping anything, by simply running a script.

I know that I can generate it by adding a document class such as following:

package 
{
    import flash.display.*;
    import flash.geom.*;

    public class Script extends MovieClip
    {
        public function Script()
        {
            var r : Shape = new Shape();
            r.graphics.beginFill(0x00ff00);
            r.graphics.drawRect(0, 0, 50, 50);
            r.graphics.endFill();
            this.addChild(r);
        }
    }
}

But is it possible to do this directly to the .flv file immediatly with some kind of a run-once script(eg, insert an exactly 800x300 red rectangle into my current scene at x=30, y=30)?; so that it appears on the document I am currently working on without running Control>Test Movie?

If so, how can I accomplish this?

VC.One
  • 14,790
  • 4
  • 25
  • 57
Dmytro
  • 5,068
  • 4
  • 39
  • 50
  • The FLV is a video format, do you mean SWF or FLA file? If you want to modify your timeline or scene in Adobe Flash, you need to use JSFL. http://help.adobe.com/en_US/flash/cs/extend/WS5b3ccc516d4fbf351e63e3d118a9024f3f-7fe8CS5.html – Nambew Apr 17 '17 at 21:00
  • fla file; I want to automate placing shapes into my project smalltalk style. – Dmytro Apr 17 '17 at 21:01
  • Have a look to this answer http://stackoverflow.com/questions/2261869/fill-figure-with-jsfl – Nambew Apr 17 '17 at 21:06
  • that shows how to do it with lines. I want to know how to add a Shape. – Dmytro Apr 17 '17 at 21:07

2 Answers2

3

Here a example with a rectangle. Save this code to a jsfl file and in editor use Commands menu and run command.

// Create Rectangle With Fill - Andrew Doll

var dom = fl.getDocumentDOM();
if (dom == null)
{
    alert('Please open a file.');
}
else
{
    // Declare variables.
    var tl = dom.getTimeline();
    var curLayer = tl.currentLayer;
    var curFrame = tl.currentFrame;
    var lockStatus = tl.layers[curLayer].locked;
    var myElements = tl.layers[curLayer].frames[0].elements;

    if (lockStatus)
    {
        alert('Unlock the layer.');
    }
    else
    {

        dom.setFillColor('#0000ff');
        dom.addNewPrimitiveRectangle({left:0,top:0,right:100,bottom:100}, 0); 
        dom.selectNone();
    }
}
Nambew
  • 640
  • 5
  • 8
  • Is there a way to add a Shape object without needing to extract the properties into a new map? – Dmytro Apr 17 '17 at 21:19
  • addNewRectangle and addNewPrimitiveRectangle use bounds object in there method signature. – Nambew Apr 17 '17 at 21:25
  • So there's no way to add a displayobject/shape using jsfl without creating it using fill and bounds? – Dmytro Apr 17 '17 at 21:35
  • The filling is optional, you just need to edit the code. I don't see the point to create a Rectangle without bounds. – Nambew Apr 17 '17 at 21:38
  • no but I'm curious if it's possible to have flash display the displayobject/shape which is already aware of its' color and bounds. – Dmytro Apr 17 '17 at 21:40
  • I don't really understand what you really want without a example. – Nambew Apr 17 '17 at 21:44
  • I want to know if it is possible to do the code I gave originally from jsfl. The code you pasted works but im curious if fl.getDocumentDOM() object has some method to render the shape using an existing shape(deduce the color and bounds by itself). It's not a big deal but I'm curious. – Dmytro Apr 17 '17 at 21:51
2

As Nambew has already replied, you can do this by utilising jsfl. The only issue I see in his code that object selection is missing, so setFillColor is not applied to an object which is drawn.

var leftPadding = 10;
var topPadding = 10;
var w = 30;
var h = 30;
var count = 10;
var dom = fl.getDocumentDOM();
for (var i=0; i<count; i++) {
    dom.addNewRectangle({left:leftPadding, top:topPadding, right:w+leftPadding, bottom:h+topPadding}, 0);
    dom.mouseClick({x:leftPadding, y:topPadding}, false, false);
    dom.setFillColor(Math.floor(16777215*Math.random())); 
    leftPadding+=w*1.1;
    topPadding+=h*1.1;
}
DigitalD
  • 586
  • 3
  • 12