FLASH FDT - What's wrong with this code - actionscript-3

Sorry my poor english
I'm a newbie in ActionScript 3.
In FLASH FDT I'm trying to load a xml file using this code:
/* some code */
var questionsURL:URLRequest = new URLRequest('questions.xml');
var loadXML:URLLoader = new URLLoader(questionsURL);
loadXML.addEventListener(Event.COMPLETE, questionsLoaded);
/* more code */
function questionsLoaded(e:Event):void {
var myText:TextField = new TextField();
myText.text = "File loaded!";
addChild(myText);
}
The problem is that the event COMPLETE is never trigged.I never
see the TextField with the text "File loaded!".
The project build successfully with no erros in FDT's Console...
The xml file is in the same folder that generated swf file
I'm using FDT Free.
Thanks for any help.

Thank you for your help.
I find the solution: the problem was related with the security settings of Flash Player.
I only have to add the FDT workspace as a trusted location for developer tests.
Sorry for my poor english.

I believe, it's because your xml file is never loaded, because of wrong path.
Add the error listeners & handlers for them to see the error reason.
loadXML.addEventListener(IOErrorEvent.IO_ERROR, urlLoaderIOErrorHandler );
loadXML.addEventListener(SecurityErrorEvent.SECURITY_ERROR, urlLoaderSecErrorHandler);
...
/* handlers code */
and add some trace output into your questionsLoaded handler for debug purposes

Related

What does the message "Test Movie Launch Failed" mean? (Flash Professional CC)

The Problem
When I was creating a test program using Flash Professional CC, I got the message "Test Movie Launch Failed" while compiling, and when I tried to open it, nothing happened and it didn't open. However, I got no compiler errors whatsoever, it just said "Test Movie Terminated." in the output.
What Might be Going on
I was thinking it might have been an error in my code, but I can't tell since the error message is extremely vague and no runtime errors appear.
So Here's my code (just in case if it's an error of the code)
Info:
Target: Air 3.6 for Desktop
Script: ActionScript 3.0
Objects:
Input Text Box with instance name of "writeT"
Dynamic Text Box with instance name of "readT"
MovieClip with instance name of "Write" (Too lazy to make buttons)
MovieClip with instance name of "Read"
import flash.filesystem.*;
import flash.events.MouseEvent;
Write.addEventListener(MouseEvent.CLICK, writeToFile);
Read.addEventListener(MouseEvent.CLICK, readFile);
var file:File = File.desktopDirectory.resolvePath("stuff.txt");
var fs:FileStream = new FileStream();
function writeToFile(e:MouseEvent):void{
fs.open(file, FileMode.APPEND);
var text:String = writeT.text;
fs.writeUTF(text);
writeT.text = "";
fs.close();
}
function readFile(e:MouseEvent):void{
fs.open(file, FileMode.READ);
var text:String = fs.readUTF();
readT.text = text;
fs.close();
}
EDIT: I commented all of my code and the error still showed up, so ignore the code
I typically see this if I use a library (.swc or .ane) that the desktop debugger cannot use.
If you using any libraries, perhaps uncouple them to see if the error disappears.
Difficult to say what the exact problem could be. From what I read, seems like a version issue. This thread maybe of some help : https://forums.adobe.com/thread/1007928
On a side note, I noticed that you have your instance named as Write and Read. I would typically avoid such names as they might conflict with reserved keywords, and while naming instances, it's best to name them using a camel case convention.
So, I would name them something Iike writeMc and readMc.
Hope this helps.
if you're publishing a mobile app, test on a mobile. you will get that error when using certain mobile-only code in the test environment. ie, test on an appropriate (ios/android) mobile.

Compiling SWF runtime from adobeAir application

I have problem in creating swf file runtime from an adobe air application. For example I create animation using https://github.com/jamesflorentino/Flip-Planes-AS3, I have converted the Sprite extension to MovieClip, the animation runs very good. Now I would like to make the animation could be save as swf file by user.
I have tried as3swf with script like this:
private function createSwf():void{
//let make example the Main class is taken from github above
var _main:Main = new Main();
// in this case i use AS3SWF plugin
var _swf:SWF = new SWF(_main.loaderInfo.bytes);
// this is for copy byteArray from the _swf convertor
var buffer:ByteArray = new ByteArray();
_swf.publish(buffer);
saveToDesktop(buffer);
}
private function saveToDesktop(_ba:ByteArray):void{
// create the file on the desktop
var myFile:File = File.desktopDirectory.resolvePath("demo.swf");
// create a FileStream to write the file
var fs:FileStream = new FileStream();
// add a listener so you know when its finished saving
fs.addEventListener(Event.CLOSE, fileWritten);
// open the file
fs.openAsync(myFile, FileMode.WRITE);
// write the bytearray to it
fs.writeBytes(_ba);
// close the file
fs.close();
}
private function fileWritten(e:Event):void{
trace("new swf file is created");
}
After all those process i got generated swf in my desktop folder with name demo.swf but when i open the file, it is only a white background with error message:
VerifyError: Error #1014: Class flash.events::NativeWindowBoundsEvent could not be found.
at flash.display::MovieClip/nextFrame()
at mx.managers::SystemManager/deferredNextFrame()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:278]
at mx.managers::SystemManager/preloader_preloaderDocFrameReadyHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2627]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/timerHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\preloaders\Preloader.as:515]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
please help me what is the best way to create swf file runtime, both from script side or command line side as long as not server side because it is desktop application.
Many Thanks
Creating a SWF at runtime is not going to be the same as taking an in memory byte array representation of an animation and saving it with a SWF extension.
If you want to build a SWF from AIR; you may consider bundling the Flex Framework with your application and use a NativeProcess to trigger mxmlc to generate a SWF. You'll need source code [or SWCs] to do this, though, it won't work with already compiled assets/classes from your running application.
Or you may want to review the file format for a SWF and go about creating it manually from your AIR application. I have no doubt this is possible, but I do not expect it to be trivial.

How to send data from flash player into an external executable through a pipe

I want to send data generated by a flash module into an external executable in windows. From what I've learnt about interprocess communication, I think it is appropriate to use pipes in this case. I am using Flash professional CS5 and when a 'trace' command is used in actionscript the ouput will be displayed in the output window in flash professional. I think Flash pipes the data into the output window and if so is it possible to obtain the handle to that pipe. Is there a way by which I can write the output from flash player itself when the trace commands are executed or the data generated on an event directly into the buffer of a pipe.
Please help me out.
Thanks in advance.
I did some tricks using a Flash Badge, AIR app. and C# console app..
We can send params to an AIR app. from BADGE and receive it using:
protected function onInit(event:FlexEvent):void{
NativeApplication.nativeApplication.addEventListener(BrowserInvokeEvent.BROWSER_INVOKE, onBrowserInvoke);}
protected function onBrowserInvoke(e:BrowserInvokeEvent):void{
//reading args
var a:String = e.arguments[0];
//Now we can run *.exe from windows using:
if(NativeProcess.isSupported)
{
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = File.applicationDirectory.resolvePath("ExecutableApp.exe");
nativeProcessStartupInfo.arguments.push(a);
var process:NativeProcess = new NativeProcess();
//dispatched when the process will be finished
process.addEventListener(NativeProcessExitEvent.EXIT,onProcessDone);
//run
process.start(nativeProcessStartupInfo);
}
else Alert.show("Native process are not supported\nPrinter settings may be wrong!");
}
It's a long way, but certainly works! At least for me it worked.

flash filereference select event not firing after using browse() and after selecting a file

This is the first time i am working in action script. I have seen a flash programmer working with it. since i know javascript i was able to work in action script.
I am creating a file upload component for my php projects.
Until now i have advanced to show the file dialog box using the FileReference api.
The select event is not firing for me. and i did not get any error.
import fl.controls.Button;
import flash.events.*
import flash.net.FileReference
var fr:FileReference = new FileReference();
fr.addEventListener(Event.SELECT,sico);
var myButton:Button = new Button();
addChild(myButton);
myButton.label = "Click Me";
myButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent)
{
myButton.label = "clicked";
fr.browse();
trace('clicked');
})
function sico(event:Event):void
{
//var file:FileReference = FileReference(e.target);
myButton.label = "selected";
trace('selected');
//trace("progressHandler: name=" + file.name + " bytesLoaded=" + e.bytesLoaded + " bytesTotal=" + e.bytesTotal);
}
The documentation said that file references should be called only during an event like mouse or keyboard.
what am i missing in the above code?
The example you posted works in Flash CS5 and Flash Player 10.3 which means the problem is not with the code.
Other potential causes of the issue could be:
The version of Flash Player which you are using is too old. FileReference requires Flash Player 9 or better. Right-click on the Flash Player or use trace(Capabilities.version) to see the version number.
Another part of the application is using a FileReference method (eg: FileReference.browse(), FileReference.upload(), FileReference.download(), FileReference.load(), FileReference.save()). Flash player 10+ allows only one file operation at a time.
If you are using a Mac, then FileReference may only dispatch the SELECT event when the SWF is run inside of a browser.
IT was like as stated by user:lukevanin in the comment section of his answer. and me too found the same. The problem was i had many frames in the timeline. since i was new to action script while toggling between F9 i was trying F5 so it created frames and it was looping continuously between that.

Loader.load and Loader.loadBytes differences

I'm loading as2 swf into AIR application. It works properly when loaded from file. But when loaded from bytes, it is broken in some way (it reacts to mouse, but some elements are inactive)
var bytes:ByteArray = ... //loaded from resources
var loader:Loader = new Loader();
var context:LoaderContext = new LoaderContext(false);
context.allowCodeImport = true; //this is neccessary
// Method 1 - blocks some scripts in loaded SWF
//context.applicationDomain = new ApplicationDomain();
// (application domain has no effect with as2 swf)
//context.securityDomain = SecurityDomain.currentDomain; //gives error 2114: securityDomain must be null
loader.loadBytes(bytes, context);
// Method 2 - loads properly
//loader.load(new URLRequest(file.url));
So why not just load it from file? My resources are protected with encryption and I can't dump them to disk - they must still be protected.
What tricks may exist to load from bytes properly?
There is similar question, but in my case as2 causes more problems.
AS2 and AS3 use different runtimes (bytecode is different) so you won't be able to properly execute any AS2 bytecode in the AS3 runtime. you are basically injecting AS2 code into your AS3 application, so it ain't gonna work :/
According the the documentation for LoaderContext you should only use the applicationDomain property only when loading ActionScript 3.0 SWFs. Try dropping that parameter (or setting it to null) and see what happens.
It seems that old SWF movies (AS1 and AS2, which require AVM1) loaded into an AIR app with load get put in their own domains, but those loaded with loadBytes share a domain. So if you have multiple AVM1 SWFs loaded with loadBytes their _global properties will clobber each other. This affects the Flash MX UI components (ca. 2002).
I can't be the only one trying to package ancient Flash files in AIR apps, so I figure this info may be useful to someone.