how to prompt for yes or no confirmation in flash - actionscript-3

I want to create an exit button in flash that when clicked will display "Do you really want to exit?"Yes or No.if yes then a countdown from 10 to 1 then exit and if no it goes back to the previous frame. can anyone please help with the code.It is for Flash actionscript 3. i tired using this
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.external.ExternalInterface;
Exit_btn.addEventListener(MouseEvent.CLICK, onClick)
function onClick(event:MouseEvent):void
{ var req:URLRequest =new URLRequest("javascript:confirm('Are you sure?')");
navigateToURL(req);}
I tried this code,it works but the popup opens up a browser page then displays the confirmation dialog,does anyone know how i can adjust this?

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

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

How to get text input to display text in Flash Actionscript 3

It's been forever since I've done Actionscript and we have a really old one that had to be redone in Actionscript 3.
It has a textinput for a search and a "search" button that will call a webpage when pressed.
My problem is that when I run it, I can enter text into the textinput but you don't see anything that you typed and I can't figure why. I've got the script to get the textinput as a variable and it goes to the test page, but I need to make the text visible in the SWF.
Here's my Actionscript:
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import fl.controls.Label;
import fl.controls.TextInput;
var searchtext = misa_stext.text;
gosearch.addEventListener(MouseEvent.CLICK, onMouseClick);
function onMouseClick(event:MouseEvent):void
{
var searchtext = misa_stext.text;
var request:URLRequest = new URLRequest("http://stackoverflow.com?" + searchtext);
request.method = URLRequestMethod.GET;
var target:String = "_blank";
navigateToURL(request, target);
}
It does what it's supposed to do, I just want the user to see what they typed and I know I'm missing something.
UPDATE:
Here's what the properties panel says:
And what I get when embedding:
But still nothing. :(
If your input does not use system fonts, you must embed the font to support dynamic text.
Press Embed... from the text input properties
Then include character ranges as needed.

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

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.