Actionscript 3 - Multiple navigateToURL() trigger multiple authorization popups - actionscript-3

I have to execute multiple navigateToURL in an swf on file:// protocol (so I can't use ExternalInterface).
Unfortunately, I can't set this swf as trusted.
I am using this code:
var urls:Array = [
'file:///tmp/1',
'file:///tmp/2',
'file:///tmp/3'
];
var timer:Timer = new Timer(300, urls.length);
timer.addEventListener(TimerEvent.TIMER, onTimer);
function onTimer(e:TimerEvent):void {
navigateToURL(new URLRequest(urls[timer.currentCount - 1]), '_blank');
}
timer.start();
Unfortunately, now flash when navigateToURL() is used in an untrusted swf, ask for permissions in a popup like this
http://i.stack.imgur.com/pWQuB.jpg
with this code, this popup appears every time navigateToURL is executed, in my case 3 times, and it makes the program unusable. I thought flash was designed to ask for permissions just once.
There's a solution to avoid this behaviour?

Related

URLLoader stuck at Open event for long time

My app loads an external URL (XML file) every 30 seconds. The app is set in startup so it starts whenever the system starts. The URLLoader stucks on the "open" event after every reboot of system. If I close the app and relaunch it, it works perfectly fine. I have added all event listeners on this URLLoader to see where is the problem. Every time it stuck at URLLoader open event. This is the straight forward code, does not seem to be any complexity. I have also tried exporting it with "Access network only" in publish settings.
private var liveFeedLoader:URLLoader = new URLLoader();
private var feedUpdateTimer:Timer = new Timer(30000);
private function init(e:Event):void {
liveFeedLoader.addEventListener(IOErrorEvent.IO_ERROR, liveFeedLoaderErrFx);
liveFeedLoader.addEventListener(Event.COMPLETE, liveFeedLoaderFx);
feedUpdateTimer.addEventListener(TimerEvent.TIMER, checkForUpdate);
liveFeedLoader.load(new URLRequest("https://s3-us-west-2.amazonaws.com/abcd/XYZ.xml"));
feedUpdateTimer.start();
}

Flash player stuck at Frame 1 after calling a function

I'm working in a flash CS6 and I'm having a trouble: After calling a function, player freezes at frame 1. This not happend during Ctrl+ENTER preview, but when I play the .swf file published (using flash player or opening it on a web browser, doesn't matter) is when the problem begin.
This is the code:
import flash.display.MovieClip;
var code:int = 0
var temp:int = 0;
var _xmlURL:String = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid=368335%20and%20u=%27c%27";
var _xmlData:XML;
function loadXML(xmlURL:String):void {
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(_xmlURL);
loader.load(request);
loader.addEventListener(Event.COMPLETE, loadData);
}
function loadData(event:Event):void{
_xmlData = new XML(event.currentTarget.data);
var dataG:XMLList = _xmlData.results.channel.item.elements();
code = dataG[5].#code;
temp = dataG[5].#temp;
trace(code);
trace(temp);
}
loadXML(_xmlURL);
I'm not used to use as3, I don't know if I'm using it right.
As you can see, the code reads an external xml file using "URLLoader" and its method ".load".
Thanks for your help.
BTW, I've already tried to play the published ".swf" file in other PCs (xp, seven, 8), one of them with Windows recently installed (seven).
Most likely (because you're loading in resources from the internet, and it works when you test), this has to do with the security settings of your application.
Go to your publish settings file -> publish settings.
You'll see a drop down labelled Local playback security. Ensure this is set to access network only and not the default acess local only.
This hangs up a lot of people when they first start using flash.
It's always good practice too, to listen not just for the COMPLETE event on your loaders, but also for error events such as:
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandlerFunction);
loader.addEventListener(IOErrorEvent.NETWORK_ERROR, ioErrorHandlerFunction);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandlerFunction);
In your case, it's probably throwing a security error.

Flash AS3 and webcam: problems with AIR

I'm having some problems getting the Flash AS3 Camera to work correctly. If you could help, much appreciated. I looked at olThe details:
I'm able, when publishing to a SWF, to get the webcam up and running and all works fine, popping up the 'may I access your camera dialog' which returns muted or not.
• First question: is there any way to make it so I can bypass the user permission, that is always grant it? We are running a kiosk app. Will the following method work for an AIR app? https://stackoverflow.com/questions/3266939/flash-grant-access-to-webcam-programmatically-behind-the-scenes
• Second question: as I said, I can get the webcam/Camera hookup to work fine when publishing for SWF in IDE, and in browser. But if I switch the project to publish for AIR and run the air app, or test in the IDE, I don't get the security permissions dialog coming up at all. Nothing. Perhaps the security box is off screen? Is there some way to control the placement? Is there something different about using the webcam from within AIR?
I'm happy to NOT publish to AIR, but to use SWF — simply need to be able to read/write to XML files on local disk and think that AIR only way to do that?
Thanks for any help!
The code:
private function initTracking() : void
{
var camW : int = 840;
var camH : int = 640;
// Create the camera
_cam = Camera.getCamera();
if (_cam == null)
{
trace("Unable to locate available cameras.");
return;
}
else
{
trace("Found camera: " + _cam.name);
_cam.addEventListener(StatusEvent.STATUS, camStatusHandler);
_cam.setMode(camW, camH, stage.frameRate);
// Create a video
_vid = new Video(camW, camH);
_vid.attachCamera(_cam);
trace("camera ", _cam, " attached to video ", _vid);
// Create the Motion Tracker
_motionTracker = new MotionTracker(_vid);
// We flip the input as we want a mirror image
_motionTracker.flipInput = true;
}
}
private function camStatusHandler(event:StatusEvent):void
{
trace("camStatusHandler::");
if (_cam.muted)
{
trace("Unable to connect to active camera.");
}
else
{
trace("able to connect to active camera.");
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler, false,0,true);
}
// Remove the status event listener.
_cam.removeEventListener(StatusEvent.STATUS, camStatusHandler);
}
If you publish as AIR, there is no security dialog (the security box for swfs is there to stop 'hackers' gaining control of a users webcam without their knowledge).
If your code works in a swf, it should also work in an AIR app without needing any changes - assuming AIR is running on the desktop and not a mobile device?
If you are not seeing the webcam output when you publish as an AIR app, post the relevant code.
Edit:
The StatusEvent.STATUS event does not occur with AIR apps - it fires when user closes security dialog - hence camStatusHandler never gets called.
So remove camStatusHandler function completely and also this line:
_cam.addEventListener(StatusEvent.STATUS, camStatusHandler);
And add important code from camStatusHandler to the end of initTracking:
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler, false,0,true);

AS3 pre-loader code not progressing

In my FLV file the first frame I have this pre-loader code:
//Stop Frame
stop();
//Create a listener to call the loading function as the movie loads
this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, loading);
//Runs when the loading progress has changed
function loading(event:ProgressEvent):void
{
//Determine the percent loaded from bytesLoaded and bytesTotal
var percent:Number = event.bytesLoaded / event.bytesTotal * 100;
//Display the percentage of the pre-loaded MovieClip
percentage_text.text = int(percent)+"%";
if(percent == 100){
gotoAndStop(2);
}
}
When I try to run the SWF file from an Xampp server via an absolute path "http://localhost/test/mainFLV.swf" the SWF does not progress past 0%. However, when I embed the SWF in a PHP script and the load that PHP script, the SWF loads, but it does not show the pre-loader progressing.
Any help?
EDIT
just tested it in Firefox, and I get a flash of the pre-loader being at 62% before it goes to the second frame. However the original problem persists in Chrome.
When you test it on a localhost the PROGRESS event fires quite often, too often, so sometimes it goes undetected. This happens if the file has been cached by the browser, too.
You should listen for event COMPLETE to decide whether the file has loaded or not.
EDIT
You can upload the file onto a slow server ;-) Or, for testing purposes, use network speed throttling software.
But honestly, if the preloader goes too fast in normal conditions (on average speed connection) that means that it is not needed. User can wait a second or two... You can use a 'spinning thing' instead.

AS3-ID3 event in a web radio

I'm building an online radio player using the AS3 code below:
private var soundChannel:SoundChannel;
private var stationUrl:String = "h t t p : / /205.188.215.230:8002/";
sound = new Sound();
sound.addEventListener(Event.ID3, onID3Change);
sound.load(new URLRequest(stationUrl));
soundChannel = sound.play();
private function onID3Change(e:Event):void
{
....
}
the sound plays successfully, but the problem is that the ID3 event is never triggered!
Does anyone know how to solve this?
ID3 doesn't exist in internet radio streams like this one. I am assuming you're talking about a SHOUTcast/IceCast stream.
For that, you need to implement the icy metadata protocol. For Flash, this is generally just done externally.
See this reference: http://www.smackfu.com/stuff/programming/shoutcast.html
Basically, you send icy-metadata: 1 in the headers of your GET request. The server then inserts metadata right into the middle of the stream, which you pull out before sending the data on to whatever is playing the stream. I'm not sure if this is even possible in Flash, but it certainly is possible to do this in PHP (or any server-side language really) and have your Flash application make a request to your PHP script to get that metadata.