Copy link to clipboard
Copied
I'm trying to learn how to make a flash element in a photoshop UI. I've managed to get one loaded and shown, but I can't seem to get extend script to send the swf file a function.
my fla file is a simple box that I'm trying to move with a button in the UI. I made it so if you click on the box it moves, and that works, but I can't get it to move with the button in the extendscript UI.
My fla code is:
import flash.events.*
import flash.display.*
import flash.external.ExternalInterface
myBox2.addEventListener(MouseEvent.CLICK,moveBox,false,0,true);
function moveBox(event:MouseEvent){
myBox2.x += 5;
}
ExternalInterface.addCallback("moveBox3",moveBox3);
function moveBox3(n){
myBox2.x += n;
};
My Extendscript code is:
#target photoshop
var res =
"dialog { \
fp: FlashPlayer { preferredSize: [550, 400] }, \
btn: Button {text: 'move box'}\
}";
var w = new Window (res,"Flash test");
w.margins = [0,0,0,0];
w.onShow = function () {
var mySWFFile = app.path + '/Presets/Scripts/flashtest.swf'
var movieToPlay = new File (mySWFFile);
try {
this.fp.loadMovie (movieToPlay);
this.fp.playMovie ();
}
catch(e){alert(e)}
}
w.btn.onClick = function(){
w.fp.invokePlayerFunction("moveBox3,10");
}
w.show()
Any ideas on what I'm doing wrong?
Copy link to clipboard
Copied
This is just a guess because I use Flex. With Flex data sent back and forth is sent as strings. In your moveBox3 function you might have to do something like this
myBox2.x += new uint( n );
Copy link to clipboard
Copied
A quick look at the tools guide leads to another suggestion. The guide says that the callback function takes 3 arguments (methodName:String, instance:Object, method:Function) and you only have two
Try
ExternalInterface.addCallback("moveBox3", this, moveBox3);
Copy link to clipboard
Copied
Thanks, Mike. With just flash, they say you can pass numbers, arrays, strings, etc. I did try using "this" in the code, but I got an error stating argument mismatch and an implicit coercion error. My this referred to the main timeline, while Adobe's sample referred to a scene. Might have to look into this more, but their code looked pretty simple, so not really sure why it didn't work like Adobe's sample script.
Copy link to clipboard
Copied
They were just quesses, as I said I don't use Flash.
With Flex the moveBox3 function would be more like this
public function moveBox3(n:Number):void{
myBox2.x += n;
}
Copy link to clipboard
Copied
Just found one issue. adobe's sample is ActionScript 2 and I'm writing ActionScript 3. so have to find a new sample.
Copy link to clipboard
Copied
Finally got it working. I redid my FLA file and used a doc class for the script rather than putting it on the first frame of the FLA file. Works great now.
Copy link to clipboard
Copied
I'm getting a Security Error within Flash when adding the callback using ExternalInterface.addCallback.
I did try to allow the localhost using Security.allowDomain("*")
Could you post your updated Flash and Extendscript code?
Copy link to clipboard
Copied
I can't seem to find my fla file. Might have been lost in computer upgrades. Two things: there are two methods for using flash. One is if your using flash builder, and the other is if your are writing ActionScript 3 code. The method with flashbuilder, I haven't been able to get to work. Also I've only used this with the swf and jsx files in the same folder, so I've never run across a security issue with the sandbox. Not sure how to resolve that. I'll see if I have the fla file on my home computer. At work right now.
Copy link to clipboard
Copied
I was just about to write you, you beat me to it.
I got it to work but honestly I'm not sure how ... At some point I created a cfg file in Flash's FlashPlayerTrust folder and shortly afterwards the security issue disappeared. I need to check whether this actually made a difference or not.
I didn't have any issue getting it to work with a Flash Builder swf BTW, I only got this error with Flash. And both my jsx and swf files were in the same directory.
In the end there wasn't anything wrong with the code itself.
Copy link to clipboard
Copied
Yes, you have to have the cfg file in the trust folder!