how do you find error in a SWF? - actionscript-3

i feel stupid asking that question, but it seems like i'm unable to find out.
i have a SWF that works perfectly inside flash. once i export as SWF, it doesn't work anymore.
i can't use "trace"
i have tryed that function but it doesn't trigger it for some reason. :
function quikTrace(string:String){
//INIT VARIABLES
var tmpTxtField:TextField;
//TEXTFIELD PROPERTIES
tmpTxtField = new TextField();
tmpTxtField.text = string;
tmpTxtField.x = stage.width / 2;
tmpTxtField.textColor = 0xFFFFFF; //white (black background)
tmpTxtField.y = stage.height / 2;
addChild(tmpTxtField);
}
is there any "outside the box" way to find errors in a SWF?

You can view trace statements in the browser by doing a few quick steps:
Get a debug flash player for your browser. link
Set up mm.cfg to enable flash logging to a file. link
Get a text editor / "tail" viewer and read the flashlog.txt file that is generated. This is where FireBug & Flashbug come in handy, if you're in firefox. You can also try baretail for PC, or regular old "tail -f" on a mac/linux machine.
Good luck.

It's not a stupid question at all! You're just learning how to debug Flash for the first time. You can use "trace" with an exported SWF by doing a debug/test build from Flash IDE or Flash Develop. You can then read these traces with Firefox by using the extentions Firebug combined with the Flashbug extension. Now you're all set for getting feedback using traces.
For this particular problem, it's hard to say. Is this function inside of a class or timeline code? If it's a class, it probably because Stage is not ready yet. You can use the event Event.ADDED_TO_STAGE to know when the Stage reference is ready to be used.
Hope this helps!

Install a debug version of flash player for your browser. It will tell you exactly which line of code is throwing error.
http://www.adobe.com/support/flashplayer/downloads.html

Related

Never Have Access to Embedded SWF Content Through Loader

I am working on embedding a SWF that is just a converted PDF created with InDesign. The SWF is 15 pages, 1 page per frame. It does include TLF text and there is no way around that unless the document is completely recreated in Flash. The problem is that when I load the SWF into my application, I never have access to the root MovieClip.
this.loader = new Loader();
this.loader.contentLoaderInfo.addEventListener( Event.INIT, this.loaderInitHandler );
this.loader.contentLoaderInfo.addEventListener( Event.COMPLETE, this.loaderInitHandler );
this.loader.load( new URLRequest( "assets/doc.swf" ) );
When I look at the loader after both the INIT and COMPLETE events as well as later on by stopping the app in debug mode, I do not see a MovieClip. Instead, the loader.content is of type doc_fla.MainTimeline__Preloader__ which contains two children, an empty Shape and another Loader. That loader, when checking INIT and COMPLETE events results in the exact same situation and it appears to be a never ending line of Loaders whose contents are "Preloaders".
Could anyone shed some light as to what is causing this or how I might fix it? I've poured a good 2 hours into solving this and I am no closer to a solution than when I started.
ActionScript Mobile project
Compiling using AIR 3.6
Testing in emulator as well as on iPad and on Nexus 7
I recompiled the SWF and embedded the TLF libraries (under ActionScript settings, just set the TLF swc which was already there to be embedded) in it and this seems to have fixed the issue. I swear I had tried that before to no success, but it worked this time.

as3 save swf stage to desktop - only works in IDE

I followed a tip here on saving the stage as a png (is there a way for flash AS3 to take a snapshot of a frame then save it as jpeg but using PNGEncoder instead). It works when run in Flash - I get a dialog box asking for where to save the file. But in a browser it just stalls out without showing the dialog box - and not running the code after that command. Are there security issues with using such code in a browser? Or is there something else going on here.
There are security issues with saving images - it has to be in response to a user action (ie mouse or keyboard event)

Flash CS6 Importing sounds

I'm working on a Flash project in CS6 and need to import a sound to my library but I'm having endless problems with it. I'm using external files in Actionscript 3.0 (e.g. I cannot do a URLRequest as it won't work externally, need to import)
I'm using a sound that should work, some errors go in that it can't be over 160kbps, this is only at 32 in the MP3 file. I converted it to an AIFF, no success, a WAV? no success.
If it's an MP3 I simply get "Couldn't import "
If it's a AIFF or WAV I get "One or more files were not imported because there was a problem reading them"
Adobe suggest you need to files under 160kbps, all are set at 32kbps to be safe.
Another suggestion said you needed Quicktime 7.7.1 (or newer) and iTunes 10.5.5.3 (or newer) for this to work with an MP3 file. I have Quick 7.7.3 and iTunes 11.0 so I really have no idea of the problem.
Can anyone help, this project needs finished quickly.
Thanks.
John.
Could be to do with bitrates.
I was running into issues with some mp3 files that I had converted from wav using Audacity. It was a specific few that wouldn't work, so I went back to Audacity and compared the working-mp3-yielding wavs to the non-working. I noticed that the working wavs had a bitrate of 44100Hz the non-working had 48000Hz. Setting the project rate ( bottom left corner ) to 44100Hz before exporting yielded mp3s that imported into flash with no problem.
In short:
48000 Hz = naughty
44100 Hz = nice
This is a weird problem here's a simple code snippet that load and play an MP3 sound AS3 doesn't support WAV natively :
//sound object
var sound:Sound = new Sound(new URLRequest("music.mp3"))
var soundChannel:SoundChannel = sound.play();
Hope this help :)
This post is kind of old but I thought I would post an answer after running into the same problem. I am also using Flash Pro in CS6. What you want to do is to embed the sound into your FLA so that when your SWF is compiled the sound will go with it. Khaled's answer is great but this issue needs a little more TLC.
What worked for me was to get an application that edits sound clips. I downloaded the open source 'Audacity.' In the bottom left corner of Audacity you can edit the project rate. Take it down to about 1600 or lower. Then save the project and export the sound as an mp3.
Finally, make sure that your sound clip is in the same folder as your FLA. Import into your FLA (this should work now) and export your sound for actionscript by right clicking the sound in the library, going to properties. Change the name of the class to whatever you want (at least get rid of the '.mp3' from the class name).
Then use the following code (which is different from the typical URL loader for sounds):
//sound is a constructor variable under your document class
public class DocumentClass extends MovieClip
{
var yourSound:yourSoundClass;
public function DocumentClass()
{
init();
}
function init():void
{
yourSound = new yourSoundClass();
}
}
Then play your sound by using yourSound.play(); This technique will embed your sound within the SWF so it will go wherever the SWF goes. I hope that helps anyone who runs into this.

AS3 Trace an info message

I'm a AS3 developer but I'm not sure how can I trace this kind of messages in firebug as an info messsages.
I know that for an error I just need to inherit for an error but I'm not sure how can I trace this kind of messages.
This code:
trace("Hola")
will show "Hola" in Firebug, but I want the fancy Info icon at the beginning also the background of the line is blue.
Thanks for your help.
you can try https://addons.mozilla.org/en-US/firefox/addon/flashbug/
years ago I've used http://www.sephiroth.it/firefox/flashtracer/ not sure if anyone uses it still.
The trick is to use Debug version of flash player
In the case where you don't want to install the Flash Debug player (performance?), rather than using trace, route it to a Debug method that traces and logs to the console:
import flash.external.ExternalInterface;
var debug:Boolean = true;
function log(msg:String):void {
if ( debug ) {
trace(msg);
ExternalInterface.call('console.log',msg);
}
}
log('Hello World');
You should be able to throw that in a frame. If you're using class definitions, you'll have to interpret that code block as snippets.
Also note that in a browser that doesn't have console.log (like IE7) this will throw an error, so maybe you should test for console.log first and store the result in a global.
Notice the debug variable. When you want to turn debug logging off, just set debug to false. This is an overly simplified idea, but provides the basic concept.
Another way enhance this concept is to include a debug "window" if you will... really just a scrollable text box on top of everything else. This is helpful when dealing with devices that do not support logging, debug versions of flash or are just difficult to debug, e.g. mobile and AIR.

Going from Flash 8 to CS3

After many years of using Flash 8, I'm moving to CS3 at work. I know I'll have to learn AS 3.0 so, does anyone have any good references or summaries of the major/most noticeable changes? Also, are there any tips/tricks for the flash environment? After spending a few minutes in CS3, I noticed that you can't directly attach actionscript to a button, which is new to me. Any other such pitfalls to watch over?
I made the total switch just about 3 months ago, here are some things that helped me ramp up rather quickly:
1) Do everything in Class files
A lot of AS3 tutorials out there deal with just code pasted on the timeline (which I can't stand because now you have to hunt for what import you need), but is fine for quick tiny stuff. In the long run it's way better work primarily in Class files. Learning how Classes work opened a huge door for me, it was the same feeling/experience I had when I first discovered Functions in AS2 :)
2) Keep graphics in library and off the workspace
Example, you have a jpg, gif, png file you just imported into your library. Made a movieClip and gave it a class name(MyButton). Now the code below will place the graphic into the workspace for you:
var myButton:MovieClip = new MyButton();
myButton.x = 6;
myButton.y = 22;
myButton.buttonMode = true;
addChild(myButton);
3) Get use to the new button code in AS3
It's something all of us new converts had to deal with painfully, but now it's a piece of cake :)
myButton.addEventListener(MouseEvent.MOUSE_UP, clickThis);
function clickThis(event:MouseEvent):void
{
navigateToURL(new URLRequest("form.html"), "_self");
//navigateToURL(request, '_self');
}
4) Make sure you remove Event Listeners after use
It took me a bit to wrap my around this one... remove em why? Oh they are still running in the background and when I listen again I'll get all kinds of mutated errors.
private function volDown(e:MouseEvent):void
{
masker.width = volControl.mouseX;
userVolume = (masker.width / 100) * 1;
volControl.addEventListener(MouseEvent.MOUSE_MOVE, volMove);
}
private function volUp(e:MouseEvent):void
{
lastVolPoint = masker.width;
setVolume(userVolume);
e.updateAfterEvent();
volControl.removeEventListener(MouseEvent.MOUSE_MOVE, volMove);
}
5) Don't forget to pass Events
I'm not a programmer by trade and this has caused so much grief, I'm glad I'm done with this birthing pain:
myButton.addEventListener(MouseEvent.MOUSE_UP, clickThis);
Since the clickThis function is launched via an Event, you have to pass: event:MouseEvent into it like so:
function clickThis(event:MouseEvent):void
Because the code below will throw the dreaded AS3 "Access of undefined property" error that new AS3 guys will always run into.
function clickThis():void
6) Read and post questions on StackOverflow... a lot!
btw I'm still a noob and originally a designer then AS2 dev, I still don't know why we put :void behind a function name.. if we have similar coding backgrounds I hope all that helps :)
I suggest you to look at the ActionScript language migration page on the Adobe devnet. It offers quite a lot articles about the key changes with ActionScript 3.
To answer your problem with the actions on a button, this no longer works (and was already with ActionScript 2 not the best way to do it). AS3 requires the code to be centralized on the timeline. So for giving a button some action, you'll need to give it an instance name and add an event listener for the CLICK event, like this:
function doSomething ( event:MouseEvent ):void
{
trace( "test" );
}
myButton.addEventListener( MouseEvent.CLICK, doSomething );
Get an Actionscript 3 IDE. Such as Flash Builder, FlashDevlop, or FDT. This will force you to learn really fast.