Flash saves in Windows, not in Linux, FileReference.save() - actionscript-3

The code below compiles fine on the Flex 4 SDK on Fedora 15. Mouse-click opens the dialog box, I click okay, and a file is saved, but the file is empty. I run the same SWF file (that was compiled on the Linux machine) on a Windows machine, and the created file contains the expected data.
Then I broke the FileReference declaration out of the function into the class level, hoping to avoid a known bug, but the same problem persists.
Hoping to set up a workaround, I added the debug Flash player to my path and ran the file from Flash without the benefit of the browser, and it works. So now a Flex problem has become a Firefox problem, maybe owing to a shady procedure I used to install the plugin without really understanding what was happening. I am running Firefox 5.0.
In essence my workflow is fixed, but perhaps people who performed the above will not be able to use projects with FileReference.save()? Should I be worried about this edge case?
/*
WriteTheFile.as
Original code by Brian Hodge (brian#hodgedev.com)
Test to see if ActionScript/Flash can write files
*/
package{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.ByteArray;
import flash.net.FileReference;
public class WriteTheFile extends Sprite
{
private var _xml:String;
private var fr:FileReference;
public function WriteTheFile():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//Calling the save method requires user interaction and Flash Player 10
stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
}
private function _onMouseDown(e:MouseEvent):void
{
fr = new FileReference()
fr.save("<xml><test>data</test></xml>", "filename.txt");
}
}
}
EDIT: was missing a line, fixed above
EDIT: addressed answer in code above, but the same problem exists.
EDIT: This works on the same system when the standalone player is invoked. Therefore this is a browser (FF 5.0) plugin problem.

Try putting the line
var fr:FileReference = new FileReference();
at class level (outside the function). Apparently this is a known bug:
http://www.techper.net/2007/12/30/flash-filereferencebrowse-problems-on-linux/

Related

Embedding png throws Error #1065: Variable FlexVersion is not defined

I've found several articles relating to variable FlexVersion and error 1065, but nothing seems to help.
EDIT:I've attempted to implement SEVERAL guides on embedding images into flashDevelop with the same result. Everything works correctly until I try to add the embedded image, then I get the above error.
Has no one here seen this error?
My Class (which I've stripped down to nothing in order to pinpoint the issue):
package {
import flash.display.Sprite;
import flash.display.Bitmap;
public class JMouse extends Sprite {
[Embed(source = "../lib/jacobsLadder.png")]
private var Picture:Class;
//private var pic:Bitmap = new Picture(); // THIS LINE
public function JMouse() {
init();
}
private function init():void {
}
}
throws the error when the line "THIS LINE" is not commented out. I've tried adding "as Bitmap" to the end of this line without luck.
I am calling this class from my document class:
jMouse = new JMouse();
the file, jacobsLadder.png, is in my lib folder, and I used FlashDevelop to "Generate Embed Code."
I am using FlashDevelop 5.0.1.3 for .NET 3.5
Any Ideas?
EDIT: I also tried this (and similar variations), as per the suggestion:
"The type of code you can run at variable declaration scope is limited. Creating an instance of Picture requires decoding and so will fail at that point. Instead create your instance of Picture within an instance methods or the constructor."
[Embed(source = "../lib/jacobsLadder.png")]
public static var Picture:Class;
public function JMouse() {
var pic:Bitmap = new Picture();
init();
}
But I get the same error.
The type of code you can run at variable declaration scope is limited. Creating an instance of Picture requires decoding and so will fail at that point. Instead create your instance of Picture within an instance methods or the constructor.
ANSWER: Load the bitmapdata with a loader.
Although the OP (me) was asking how to embed the file, the mysterious problem of "Error #1065: Variable FlexVersion is not defined" issue is apparently an insurmountable one, and I hope that anyone else who may come across this problem may find solace in the following (courtesy of John Mark Isaac Madison et al):
How do you load a bitmap file into a BitmapData object?
While not the an answer, per se, it at least allows the OP to continue on in his work as an alternative to lighting his house on fire.

Why isn't this embedded sound file playing?

I've been going through a few tutorials, trying to find how to embed audio files and play them in AS3, and they tend to show examples which are very similar. However when I try to use these examples, nothing is played. My mp3 file will be embedded successfully, all the lines of code will execute sucessfully, but there will just be no sound. Take the following code, for instance:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Sound;
public class Main extends Sprite
{
[Embed(source='/../lib/Kalimba.mp3')]
private var MySound : Class;
private var sound : Sound;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
sound = (new MySound()) as Sound;
sound.play();
}
}
}
What's going wrong here? Many examples online basically use this code, just changing variable names and the like. I'm using FlashDevelop, in case that makes any difference. Thanks.
EDIT
Apparently it's somehow linked to that file. I tried Kalimba.mp3, Maid with the Flaxen Hair.mp3, and Sleep Away.mp3, all of which are Windows 7 defaults in Libraries\Music\Sample Music. None of them worked. Then I downloaded a random mp3 file elsewhere and tried to use it, and it worked just fine (Blackbird Blackbird - Heartbeat.mp3 from http://www.last.fm/music/+free-music-downloads/sample). I have tried using converters to make sure Kalimba was at 44100 Hz with a bitrate of 128 kbps, but that didn't seem to work. What's the difference?
It worked perfectly for me with your code. Check your mp3 file. Try a different file and see if it works.
Also check for silly mistakes like:
Have you used addChild() to add instance of Main class? The init() in your Main.as will fire only after you've added it to display list
Is the pathing in your source correct? I've changed my path to "test.mp3", put your mp3 in a root folder to be sure.

AIR iOS app hangs when clicking button inside imported swf

Been bangin my head against a wall all day, thought I'd see if anyone can shed some light on this -
I have an iOS air app that imports a remote swf. Once imported, an event listener is added to a button inside the imported swf. Clicking the button causes the app to hang. Here's some code -
private function loadRemoteSWF():void{
var urlRequest:URLRequest = new URLRequest("http://www.domain.com/remote.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(urlRequest);
}
private function onLoaded(e:Event):void{
var loaderInfo:LoaderInfo = e.currentTarget as LoaderInfo;
var adPanel:MovieClip = loaderInfo.content as MovieClip;
adPanel.continueButton.addEventListener(TouchEvent.TOUCH_BEGIN, onContinueClicked);
addChild(adPanel)
}
private function onContinueClicked(e:TouchEvent):void{
trace("onContinueClicked");
}
I'm using Flash Builder 4.7 AIR SDK 3.5 ASC 2.0.
This only happens on a release build, debug builds work fine so near impossible to find the cause. It also works fine when using the legacy compiler on the same SDK version.
Dispatching a touch event programatically on the button also works fine. (thought I could do a try/catch to find an error)
adPanel.continueButton.dispatchEvent(new TouchEvent(TouchEvent.TOUCH_BEGIN));
Touching the button just kills the app, it doesn't even hit the trace.
Anyone got any ideas how to debug this, or why this problem might be happening?
Thanks
Dave
can you do a test: instead of using the the native loader, try using an API, like greensocks api - SWFLoader.
Also, try setting the accepted domains through the security class prior to loading the swf file:
import flash.system.Security;
public class Main extends MovieClip{
public function Main(){
Security.allowDomain("*");
}
}
I would suggest trying to compile with the same setup on a different machine, just to make sure that the Builder install doesn't have some issues.
Also, have you tried on different devices, (could be an issue with the device you are using)?

AS3:loading XML is not working after exporting the air file?

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
names();
function names()
{
var url:URLRequest = new URLRequest("http://artbeatmedia.net/application/xmlkpisname.php?username=adel_artbeat&password=ADL1530");
url.contentType = "text/xml";
url.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.load(url);
loader.addEventListener(Event.COMPLETE, onLoadComplete);
}
function onLoadComplete(event:Event):void
{
trace('good');
}
i used adobe air to load xml using as3,this code works only in the .fla file,but when i export the .air file it does not work.
if you export a program, trace messages won't be visible.
you can still use MonsterDebugger, but thats a security hazard.
Vizzy tracer will still capture trace calls from an Air app. Get Vizzy from Google code
I tried your code with no modifications just now and it worked just fine, so I suppose your problem is just a failed trace out. Have a go, Vizzy shows even traces from within Flash IDE, so see what happens. If it still fails, then it might be some connection/permission issue.
Are you including the XML file when you publish the AiR app? Happened to me once, forgot to include the file in the publish dialogue....an hour of my life I'll never get back.

Is it possible to create a flash movie from only actionscript?

Currently I am mostly a PHP/Javascript/CSS/HTML applications programmer. But I would like to start learning how to create flash movies also. However, I do not want to spend the money to get CS4. Can I create flash movies from only Actionscript 3? Or would anyone recommend that I jump straight to air? All of the different adobe products, which do the same thing, confuse me.
I just do not want to jump into it and then find out that I have to spend 900 dollars for the IDE. I really just want to code, and not have to use the IDE.
Thanks,
Metropolis
Yes, you can create .swf files using only ActionScript if you use the Adobe's free Flex SDK. Even though it's the Flex compiler, it can be used to compile pure ActionScript programs.
Flex is an advanced UI toolkit built on top of Flash, which makes it easier to build applications with complex user interfaces in Flash. Flex applications are written in ActionScript and a HTML-like XML format (which is actually converted into ActionScript by the compiler behind-the-scenes). AIR is a platform that allows you to build standalone Flex applications that run outside of a web browser. I've never looked into if you an make a pure ActionScript AIR application, but my guess is no.
Here's an example of a hello world program in pure ActionScript. Save it in a file called Test.as and compile with the command line mxmlc Test.as.
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Test extends Sprite {
public function Test():void {
var tf:TextField = new TextField();
tf.text = "Hello, world";
addChild(tf);
}
}
}
FlashDevelop is an IDE for the Flex SDK. You still need to install the Flex SDK in order to use it.
I advise you to look at the Haxe community.
Haxe is a language & compiler that can do a lot of things. It is fully open source and you can create .swf files with it without the need for CS4.
The community is driven by the author or MTASC which was the first open source ActionScript2 compiler.
Haxe is now fully compatible with AS3 & Flex I believe.
check http://haxe.org/
I Hope this will help
Jerome Wagner
Use FlashDevelop :)
Here's the same code as tmdean's entered in Main.as when you create a new AS3 project in FlashDevelop.
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var tf:TextField = new TextField();
tf.text = "Hello, world";
addChild(tf);
}
}
}
You do need a Java 1.6 JRE to compile with the Flex SDK and an Adobe Flash Player (Debugger version) to view your compiled SWF file (get the one that says Windows Flash Player 10 Projector content debugger if you're running Windows).
Details on the configuring FlashDevelop for AS3 development can be found at the FlashDevelop wiki.