adding event listener of the closing and changing the FLA document for the SWF extension panel. using ActionScript, JSFL - actionscript-3

I have an extension SWF panel and a list of movie clips of the currently open document on it. I want to clear my list when the user closes the current document. Also, I want to add some alert "You have to select the previous document you were work on" - when the user selects other open .fla document and tries to press some button on the SWF panel to edit some MC from the list. So I want to know if has Adobe Animate the ability to listen to closing and changing of documents?
thank you for advance for any hints

an answer from adobe community support:
Yes, there is such a possibility. You can register a javascript function to be executed when certain system event occurs:
enter code herefl.addEventListener( eventType, callbackFunction );
The possible system events are:
"documentNew", "documentOpened", "documentClosed", "mouseMove", "documentChanged", "layerChanged", "timelineChanged", "frameChanged", “”, "prePublish", "postPublish", "selectionChanged", and "dpiChanged".
Also, in Flash CS4 and above, you have the possibility to refer a particular swf panel. In combination with ExternalInterface class and MMExecute method in AS, you can build a two-way communication between the two environments.
Example:
// JSFL
var docChangedID = fl.addEventListener( "documentChanged", onDocumentChangedHandler );
function onDocumentChangedHandler(){
var panel = fl.getSwfPanel( "<my panel swf file name >", false );
panel.call( "AScustomEventName" );
}
// AS
import adobe.utils.MMExecute;
import flash.external.ExternalInterface;
ExternalInterface.addCallback( "AScustomEventName", this.myASMethod );
function myASMethod() : void {
// your stuff here
MMExecute( "some jsfl code or path to a jsfl script" );
}

Related

Adobe CC Flash AS3 Click tag

I recently switched over from Adobe CS6 to Adobe CC. In the new Adobe CC Flash, it no longer supports action script 2. I need to create an AS3, click tag. Is there a universal AS3 clickTag code you know of that is used? I've googled it, but found some unreliable results.
I'm assuming that you mean you want to have a button react to a click? If so, you simply have to create a button object, and then add a listener for that button where you choose 1) the event you want to listen for, in this case a click, and 2) the code you wish to execute when that event is fired, in most cases this is a function call.
For exaxmple, the following code was placed on the first frame of an .FLA:
import flash.events.MouseEvent;
var myButton:SimpleButton = new SimpleButton();
var myButtonSprite:Sprite = new Sprite();
myButtonSprite.graphics.lineStyle(1, 0x555555);
myButtonSprite.graphics.beginFill(0xff000,1);
myButtonSprite.graphics.drawRect(0,0,200,30);
myButtonSprite.graphics.endFill();
myButton.overState = myButton.downState = myButton.upState = myButton.hitTestState = myButtonSprite;
myButton.addEventListener(MouseEvent.CLICK,buttonClickHandler);
addChild(myButton);
function buttonClickHandler(e:MouseEvent):void {
trace("YAY! My Button was clicked!");
}
To give credit where it is due, the code for creating the button dynamically that you see above is showcased here: Create a Button with only code AS3
If you already have a button on your stage that you want to wire up with a click event you simply have to give the button an instance name and then use that instance name in the code. In the following example, the instance name of the button on the stage is myButton:
myButton.addEventListener(MouseEvent.CLICK,buttonClickHandler);
function buttonClickHandler(e:MouseEvent):void {
trace("YAY! My Button was clicked!");
}

How to play two swf files in as3

hai i want play two swf files in my action script project.In this two files one swf file works on the detection face in front of the system.Other swf plays the flv file.when face is detected player must be stooped if not player must be plays the flv file.
I know how to load the swf file but i cant handle the functionality regarding starting and stoping player.
the snippet of code shows how can i load external swf file .and i will explain each line of code in comments
public function videos(view:Sprite)
{
this.box = view;//IT GETS Sprite object from other class because of need to display the player also.
request = new URLRequest("Untitled-1.swf");
currentSWF=new MovieClip();
loader= new Loader();
loader.load(request);
box.addChild(loader);
currentSWF = MovieClip(loader.content);
loader.addEventListener(Event.COMPLETE,loadComplete);
//addChild(loader);
currentSWF.gotoAndPlay(1);//when i put this line of code in comments it plays the external swf also.
}
I hope u understand my doubt .can any one explain how to handle my things .i am new to this action script.please help me
Loaded files automatically play, unless you tell them explicitely not to. You’ll have to listen to the Event.INIT event, and stop the movie there:
loader.AddEventListener(Event.INIT, initLoader);
function initLoader (event:Event)
{
MovieClip(event.currentTarget.content).stop();
}
This will stop the movie before it is attached to the stage, and before it starts playing—so it won’t do that unless you start it again.
Note that you shouldn’t access loader.content in any way before the INIT or COMPLETE events, as it’s very likely that the content isn’t loaded then. As such you should put all your manipulating actions into the COMPLETE event:
box.addChild(loader);
loader.addEventListener(Event.COMPLETE, loadComplete);
function loadComplete (event:Event)
{
// Now it’s safe to access the `content` member:
currentSWF = MovieClip(loader.content);
// Of course this one would play the movie again, so you probably want
// to call that later on a button click or something.
currentSWF.gotoAndPlay(1);
}

ActionScript: To perform non graphical operations

As I understand, ActionScript is used mostly to control graphical output on Flash websites: such as Flash based games.
However, I would like ActionScript to perform tasks not related to graphical output. Tasks, which for browser compatibility reasons, are more suitable for ActionScript: such as file upload.
Is it therefore possible to use ActionScript instead of JavaScript or to accomplish tasks that are not possible with JavaScript, such as file upload?
Are the following possible?
Run ActionScript on HTML Button Press?
Send information to ActionScript from HTML/JavaScript?
Process information without any graphical output in ActionScript?
Ouptut information from ActionScript to HTML/JavasScript?
I wish to know, if ActionScript can do what I wish.
I will have a picture of the right functions to call.
ExternalInterface is your friend:
http://help.adobe.com/nl_NL/Flash/CS5/AS3LR/flash/external/ExternalInterface.html
Some tips when using ExternalInterface:
set allowScriptAccess to "always" in the html embed code
make sure the flash has an id in your html code
Some simple examples:
1. Grab a value from javascript to flash
// actionscript 3 code
if (ExternalInterface.available)
{
var url:String = ExternalInterface.call("document.location");
// output to textfield
var t:TextField = new TextField();
addChild(t);
t.text = url;
}
2. Call a function with parameters from flash
// actionscript 3 code
if (ExternalInterface.available)
{
var result:String = "Flash rocks"
ExternalInterface.call("alert", result);
}
3. Call from javascript a function with parameters to Flash:
// javascript
window.onLoad = function()
{
document.getElementById('flashId').doSomething("javascript rocks");
}
.. and
// actionscript 3
if (ExternalInterface.available)
{
ExternalInterface.addCallback("doSomething", handleSomethingFromJavascript);// links js function to as3 function
function handleSomethingFromJavascript(value:String):void
{
// output to textfield
var t:TextField = new TextField();
addChild(t);
t.text = value;
}
}
You can do lots of stuff between flash and javascript, as you can see the intergration is almost painless! The only note is that within flash ExternalInterface is not available, so you have to test in browser. You can make a transparent Flash object using wmode="transparent". You cannot use display:none or visibility (css) because then the flash isnt executed or acts slower. To make sure it keeps running, place it position:fixed (css) on the page in a corner or something. Browsers make flash object run in a sort of sleep mode (slower) when out of screen or when inactive (ie in an inactive tab)
You can't really replace javascript with actionscript, but you can interact with it.
"Run ActionScript on HTML Button Press?" - Yes, this is possible through ExternalInterface.registerCallback. However, many actions (iirc, opening the file browser) can only be done on user interaction in flash, so you would need a flash button for that.
"Send information to ActionScript from HTML/JavaScript?" Also through externalInterface, or flashvars (but only at startup).
"Process information without any graphical output in ActionScript?" - It's a programming language, so sure. What did you have in mind?
"Ouptut information from ActionScript to HTML/JavasScript?" - yes, also through ExternalInterface.

How could I compile the code for this Flash tutorial?

I started reading this tutorial: http://active.tutsplus.com/tutorials/actionscript/creating-a-reusable-flash-uploader-with-actionscript-3-0-and-php/
I'm using FlashDevelop, and I pasted the full code into an ActionScript file. The errors I'm receiving are like this:
C:\Users\tempus\Documents\uploaderas\Uploader.as(30): col: 4 Error: Access of undefined property select_btn.
select_btn.addEventListener( MouseEvent.CLICK, browse );
^
C:\Users\tempus\Documents\uploaderas\Uploader.as(31): col: 4 Error: Access of undefined property progress_mc.
progress_mc.bar.scaleX = 0;
...
I understand that the errors appear because the objects have not been declared ( and they appear to be instantiated from somewhere ), but I don't understand how/what should I include to declare them. Could you point me towards a solution?
It's because the buttons are created in the Flash IDE (as the tutorial was meant to be compiled using the Flash IDE). Since the buttons don't exist in the code aspect you get that error.
You can either create the elements yourself via code, or use the Flash IDE and export a swc/swf of the neccessary UI elements and include that in your flashDevelop project. I'm assuming you'll want to do the latter -
in the Flash IDE, open the .fla, open the library panel, find the progress asset, right click it and bring up the properties. Check the "Export For ActionScript" option, then in the 'Class' field give it a unique name like "SelectBtn". Do the same for the 'progress' asset (only a different class name like 'ProgressBar'). Go to the flash publish settings, and on the flash tab select 'export swc'. publish the file and place the published swc in your flash Develop project folder (traditionally the lib folder of your project).
In Flash Develop, right click your swc and choose 'Add To Library'. (You may need to right-click again and go to options and choose the include completely option). Now you can access those classes you setup in Flash. Then in your code, declare and initialize the display assets:
public var select_btn:SelectBtn = new SelectBtn();
public var progress_mc:ProgressBar = new ProgressBar();
You'll also need to do that textField too. It would be easiest just to do it in your code though.
public var label_txt:TextField = new TextField();
Keep in mind you'll need to manually position and use addChild on all three elements this way. If you want to keep the positioning that's in flash, just select all the elements on the stage and press F8 to convert them to a MovieClip. Then in the library setup linkage the same as the others and give it a class name of something like "DisplayAssets" and export a new swc. Then your code would look like this:
public var select_btn:Sprite;
public var progress_mc:Sprite;
public function Uploader(){
var displayAssets:DisplayAssets = new DisplayAssets();
addChild(displayAssets);
select_btn = displayAssets.select_btn;
progress_mc = displayAssets.progress_mc;
//the rest of the code
}

AS3 ScrollPane dispatch event to content

i've loaded external swf into ScrollPane and i need to dispatch click event to this external swf. is it possible? ScrollPane.content.dispatchEvent(new MouseEvent(MouseEvent.CLICK,true)); doesn't work. this is obvious cuz ScrollPane.content is an DisplayObject and it have not CLICK event...
I can't use MovieClip as container for external swf cuz external swf is a documents converted to swfs using openoffice and it doesn't want to load inside MovieClip but perfectly loads inside ScrollPane and react on mouse clicks,but i need to simulate mouse click on it.
so you're saying that the following won't work or you haven't tried it?
var exSWF:MovieClip = MovieClip( ScrollPane.content );
or
var exSWF:Sprite = Sprite( ScrollPane.content );
Not sure to understand what you mean when you say that your external SWF won't load into a MovieClip.
Do you know what version of Actionscript was used for the external SWF, you can check that in debug mode by looking at the properties of the ScrollPane.content?