Using Actionscript 3.0 to play audio from dropbox - actionscript-3

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

Related

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");
}

Im trying to write a program which loads external resources with metadata tags in As3

ive been given some work to do but i cant seem to understand why its not working..
I think im using a wrong approach,
Im trying to load a picture and a movieclip on the same stage..
Though ive managed to display a picture, but when i try to display a MovieClip.. There arent errors though when i run i get the following:
TypeError: Error #1034: Type Coercion failed: cannot convert LoadingFiles_MovingStars1#2aba161 to flash.display.Bitmap. at LoadingFiles()[C:\Users\user\Adobe Flash Builder 4.5\LoadingFiles\src\LoadingFiles.as:28
Here is the code,
package
{
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.display.StageScaleMode;
[SWF(width = "800", height = "600", frameRate = "30", backgroundColor="#FFFF00")]
public class LoadingFiles extends Sprite
{
[Embed(source="/../assets/Head.jpg")]
protected var MovingStars:Class;
[Embed(source="/../assets/water1.mp4", mimeType = "application/octet-stream")]
public var MovingStars1:Class;
public function LoadingFiles()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
// swf
var myStars:Bitmap = new MovingStars();
var myPic:Bitmap = new MovingStars1(); //
var yourPic:MovieClip = new MovingStars1();
myStars.x = (stage.stageWidth-myStars.width)/2;
myStars.y = (stage.stageHeight-myStars.height)/2;
addChild(myPic as MovieClip);
addChild(yourPic);
addChild(myStars);
}
}
}
Now ive written that code, but it doesnt work..
Im really stressing because im falling behind by a bit in class..
Help would greatly appreciated.
Thank you.
You're trying to instantiate an embedded .mp4 file as a Bitmap or a MovieClip. That's not possible, you need to create a video player or use an already existing videoplayer component.
Here's a more in-depth answer on that:
How to make an AS3 Flash video player?
When you embedded image
[Embed(source="/../assets/Head.jpg")]
protected var MovingStars:Class;
Your MovingStars is BitmapAsset class. This is class included in Flex SDK. So you need preload Flex SDK rsl's. Or configure Flex SDK libraries linking as merge in to code.
What IDE are you using?

classpath in as3 flashdevelop

I am very new in AS3. I use FlashDevelop 4. I have no Adobe Flash, just FD (pure AS3) I have problems with classpath. I searched the database but I found nothing that could help me. So the problem is as follow.
I have the project "Testing" in C:\AS App\Testing with the file Main.as. I have, also, the folder C:\AS App\W_T. In this folder is the file write_text.as. The file Main.as looks like that:
package
{
import flash.display.*;
import flash.text.TextField;
import flash.events.*;
import W_T.write_text;
public class Main extends Sprite
{
var t:TextField=new TextField();
public function Main():void
{
stage.addChild(t);
stage.addEventListener(MouseEvent.CLICK, write);
}
public function write(me:MouseEvent):void
{
var wt:W_T.write_text = new W_T.write_text();
t.x = 100;
t.y = 100;
t.text = wt.output();
}
}
}
The file write_text.as looks like that:
package W_T
{
import flash.display.*;
import flash.text.TextField;
import flash.events.*;
import W_T.*;
public class write_text
{
public function write_text()
{
}
public function output():String
{
var txt:String;
txt = "From function !";
return(txt);
}
}
}
I make the appropriate specification in the global classpath. But I get the following errors:
Error: Type was not found or was not a compile-time constant: write_text.
var wt:W_T.write_text = new W_T.write_text();
Error: Call to a possibly undefined method write_text.
var wt:W_T.write_text = new W_T.write_text();
Definition W_T:write_text could not be found.
import W_T.write_text;
Could you help me please to find where I have done wrong ?
Thank you.
EB
The problem is the compiler isn't finding your write_text.as file. By default, it will be looking here:
C:\AS App\Testing\W_T\write_text.as
Try adjusting accordingly and see if it works. When you declare package W_T { } flash will look in a subfolder called W_T for a file with the same name as the public class.
When you declare just simply package { } with no name, it will look in the root of your class library path, which seems to be a folder called Testing if that's where your main.as file is living.
If you wanted to use a common folder for your class files (that isn't nested in an individual projects folder), you can tell flash develop where to find them by going to: project -> properties, then the Classpaths tab. By default flash develop will only look in folders relative to the project.
The problem is that you haven't told the compiler (flex?) where to find the file. When you add it as classpath you only tell flash develop where to find the file, not the compiler.
First of all you have to check how you compile and secondly how you can change and add classpaths for your solution.u
I usually do this through ant script and a build.xml file and I can't unfortunately remember how the "pure as3"-projects are working in regards to compiling

flashfirebug As3 console timer or setInterval not working

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.

Access the main timeline in a swc

I have some animation that was created in the main timeline in an FLA
I want to publish this as a SWC for importing via Flash Builder.
However- I can't find a way to do this. Any ideas?
The only workaround I know of so far is to copy all the frames into a movieclip symbol and then set that to "export for actionscript" This isn't ideal since then I need to reposition the entire animation so it's at 0,0- and since there are objects moving outside the bounds of the stage, etc. I'll have to do it by eye. Not ideal :\ so a better solution is much appreciated!
You could embed a .swf
package {
import flash.display.MovieClip;
import flash.display.Sprite;
public class Demo extends Sprite{
[Embed (source="test.swf")]
private var Test : Class
public function Demo() {
var test : MovieClip = new Test() as MovieClip;
addChild(test);
}
}
}