flashfirebug As3 console timer or setInterval not working - actionscript-3

i have tried to use a timer in the as3 console from FlashFirebug addon but it doesn't work (have tried several combinations). The timer code was this:
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
var myTimer = new Timer(1000, 2);
myTimer.addEventListener(TIMER, timerHandler);
myTimer.start();
function timerHandler(event:TimerEvent){trace("timerHandler: ");}
//but it gives this error:
Error #1034: Type Coercion failed: cannot convert r1.deval.rt::FunctionDef#50ef781 to Function.
//also have tried with setInterval with this code:
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
import flash.utils.setInterval;
function d(){trace("cc");}
setInterval(d, 2000);
//but console error says:
Error: Call to a possibly undefined method.
//probably need to import something. tried tho import "import flash.utils.setInterval;" but gives this error:"Error: You must import the class before being able to instantiate it. Ex. import flash.display.MovieClip;"
Can you help me on This? timer or setInterval functions?
Thanks,
John

I'm not sure about the error message you're getting, but you do have an error in your code at the point at which you assign the event listener for your timer. You need to access the event name constant from the TimerEvent class like so:
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
var myTimer = new Timer(1000, 2);
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
myTimer.start();
function timerHandler(event:TimerEvent){trace("timerHandler: ");}
There's a decent explanation here on the advantages of using the ActionScript 3.0 Timer class over setInterval.

Well, looks like there is no way to achieve this. FlashFirebug uses D.eval library and I can't find that it supports timers or intervals right now.

I'm not sure you've sorted it yet but it looks like:
var num:int = setInterval(d, 2000);
and if you import import flash.utils.clearInterval; you can stop it like:
clearInterval(num)

The problem is on this line:
myTimer.addEventListener(TIMER, timerHandler);
It should be:
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
// add this ^^^^^^^^^^^

This is quite old. But answering it to help anyone in the future.
FlashFirebug 4.8.0 which is still on the approval queue (at the time of answer) should enable you to inject an SWF file inside the running SWF.
That would allow you to use full AS3 capabilities when you hit limitations with the console.

Related

Using Actionscript 3.0 to play audio from dropbox

Just looking for some advice and hoping someone can point me in the right direction.
I'm trying to create a Flash MP3 player that can play music stored on DropBox. Never used ActionScript before so kind of learning as I go...
From what I've read so far, I need to use URLRequest to get the link to the mp3 file, then use the Sound object to load the file and play it. However, when I test my SWF file I don't get audio. I've also been reading about URLSream and NETstream, but not sure how to use that with the Sound object. I'm not 100% sure if I'm using Sound correctly, and given that this is pretty old technology now, I'm struggling to find decent tutorials.
Here's the code I've been trying:
package {
//Dependencies
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.net.URLStream;
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.media.*;
//Class code
public class soundObject extends MovieClip {
//Variables
var mySong:Sound = new Sound();
//Init Code here
public function soundObject() {
var myRequest:URLRequest = new URLRequest("https://www.dropbox.com/s/[dropboxurl]/T-U-R-T-L-E%20POWER.mp3?dl=0")
mySong.load(myRequest);
mySong.addEventListener(Event.COMPLETE, onSoundLoad);
}
private function onSoundLoad(e:Event): void
{
mySong.play();
}
}
}
So I figured it out guys... and surprise, surprise, it was something rather simple.
In publish settings, I had it set to 'local only'. When I changed this 'network only' the link started to magically work.
Thanks for the help. Got there in the end :D
EDIT: And just in case, I did also have change ?dl=0 to ?dl=1

Why can't I remove this Movieclip?

I have a TouchEvent function onTouch inside the constructor function of a item_Potion class that gets run when a Movieclip is touched. This function goes through a series of unrelated checks and then in the end it is supposed to remove itself (the Movieclip).
At the end of the onTouch function it is supposed to remove itself by doing the following:this.parent.removeChild(this);
However, this does not work.
I get the following error message:
TypeError: Error #1010: A term is undefined and has no properties.
at Function/item_Potion/$construct/onTouch()[E:\Clients\org\tcdsb\ZenithsReach\item_Potion.as:56]
at runtime::ContentPlayer/simulationSendTouchEvent()
at runtime::SimulatedContentPlayer/clientSocketDataHandler()
The line it's reffering to for the error message (Line 56) has the following:
this.parent.removeChild(this);
My imports:
` import flash.display.Stage;
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.*;
import flash.events.TouchEvent;
import flash.net.dns.AAAARecord;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;`
I know the problem is not with the other portions of my code because I have tried switching this line out with visible = false; and I get no errors. Therefore, I am certain that the issue is with the way I am removing the MovieClip, and that is where I need help.
Similiar Sources I have tried that do not work:
How to make a MovieClip remove itself in AS3?
parent is undefined in your example, hence the error "a term is undefined...".
You can avoid the error by wrapping your code in:
if (parent) {
parent.removeChild(this);
}
But based on your comment providing [object global] is sounds like you might actually want something like:
event.currentTarget.parent.removeChild(event.currentTarget);
Which would remove the object that the touch event listener was added to.

translate an actionscript2 into an actionscript3

i'd like to convert this actionscript 2 instruction:
button_btn.onRelease = function():Void
{
getURL('javascript:shrinkSkinOverlayDiv()');
}
to an actionscript 3 one.At the moment i'm using adobe flash-cc which doesn't support actionscript 2 actions anymore. Since i'm really noob with flash, i need some help (accepted a work from my boss which i can't even accomplish :P).
For your button, use addEventListener() to listen for MouseEvent.CLICK events.
To call a JavaScript function, use ExternalInterface.call().
import flash.events.MouseEvent;
import flash.events.Event;
import flash.external.ExternalInterface;
button_btn.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:Event):void {
ExternalInterface.call("shrinkSkinOverlayDiv");
}

Adding the same function to multiple buttons in Actionscript 3.0

I am trying to add the same button function to 2 different symbols in Flash. One is the logo and the other is text that I converted to a symbol that will show itself during the end scene.
I don't understand what I am doing wrong, but I am extremely new to Actionscript & Flash.
My code looks like this:
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.net.navigateToURL;
import flash.net.URLRequest;
myButton, txtButton.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
function onClick(e:MouseEvent):void{
navigateToURL(new URLRequest("http://www.true.land"), "_blank");
}
But I am getting this error:
Attempting to launch and connect to Player using URL
C:\Users\Angela\Desktop\ASU\GIT 314\Assignment
7\AngelaRogers_Assignment7.swf [SWF] C:\Users\Angela\Desktop\ASU\GIT
314\Assignment 7\AngelaRogers_Assignment7.swf - 351066 bytes after
decompression TypeError: Error #1009: Cannot access a property or
method of a null object reference. at
Button/frame1()[Button::frame1:7]
You must write it twice - once for each button, starting with only it's name: child.addEventListener. There is no shortcut to add the same for two objects at once.
You can write a shortcut function to do this easily enough. (As pointed out by others, your comma is what is causing the error). This I believe is more what you're after: (especially if you keep adding more buttons).
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.net.navigateToURL;
import flash.net.URLRequest;
addClick(myButton, txtButton); //you can add as many items as you want as parameters
function addClick(...buttons):void {
//the ...buttons parameter is known as the '...rest' parameter, and is an array of all the parameters passed to the function
for each(var btn:Sprite in buttons){ //loop through all the items passed in and add the listener
btn.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
}
}
function onClick(e:MouseEvent):void{
navigateToURL(new URLRequest("http://www.true.land"), "_blank");
}

How to convert a two-file preloader and game swf with Document class into single swf?

I have a game that I've made that runs in two files, one the preloader and one the swf. When I use these two files together they work fine, however some flash portals require only one SWF, so I'm trying to find the shortest-path way to convert it to use only one.
The game swf uses a Document Class that includes the package, class constructor, and tons of functions, and runs fine. I have lots of movieclips on the stage that I refer to in my code. The code is something like this (abridged):
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
...
public class Game extends MovieClip {
var EnemyArray:Array;
var HeroArray:Array;
...
public function Game() { // class constructor
EnemyArray = new Array();
addEventListener(Event.ENTER_FRAME,onEnterFrame);
mainRestartButton.addEventListener(MouseEvent.CLICK, RestartLevel);
...
}
public function KeyPressed(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.SPACE)
{
attack();
...
}
} // End of class
} // End of package
I also have another swf, my preloader, which has the following code in frame 1:
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.ProgressEvent;
import flash.events.Event;
var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoading);
var myURL:URLRequest = new URLRequest("Game.swf");
myLoader.load(myURL);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
function onLoading(event:ProgressEvent):void {
var loaded:Number = event.bytesLoaded / event.bytesTotal;
percent_txt.text = "Loading: " + (loaded*100).toFixed(0) + "%";
}
function onComplete(event:Event):void {
myLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onLoading);
myLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
this.addChild(myLoader);
}
I've been through the gamut of solutions online and none of them seem to work with the way that my code is set up, such as: How to create Preloader in AS3
I tried his option 1 by taking all the code in my Document Class other than the package and constructor and pasted it into frame 2. However it returns "Error #1009: Cannot access a property or method of a null object reference." for any references to items on the stage, such as:
mainRestartButton.addEventListener(MouseEvent.CLICK, RestartLevel);
As he mentions, "This works well if you organized your project in a way that the most of the assets (images, etc) are in the Flash IDE Library and are not loaded on the first frame (you can check that in each library item's properties)." My project is NOT organized in such a way.
What is the easiest way for me to reorganize my FLA/code so they can have a preloader in a single swf?
Thanks so much for your time and help!
I use FlashDevelop (no FLAs) so I'm not sure if it'll work for you but I use the solution described here.