Passing URL Params to new browser window/tab on USB drive from Flash moviclip - actionscript-3

I'm running a website from a USB drive and trying to pass parameters through the address bar to a new window when a button is clicked in the embedded flash swf.
The problem is that on some workstations the parameters are stripped from the URL. On others it works fine.
I have a movieclip button that when clicked calls this function:
function onReleaseHandler(myEvent:MouseEvent) {
var printURL = "html/certPopup.html";
var request:URLRequest = new URLRequest(printURL);
var variables:URLVariables = new URLVariables();
variables.vModTitle = modTitle;
variables.vFirstName = firstName;
variables.vLastName = lastName;
variables.vLang = language;
request.data = variables;
navigateToURL(request, "_self");
}
On machines where this is working, the certPopup.html page opens in a new tab and the URL in the address bar looks like this:
file:///G:/courses/flash/1/EN/course/html/certPopup.html?vFirstName=Charlie&vModTitle=This%20is%20the%20Title&vLang=EN&vLastName=Brown
On workstations where this is not working the URL in the address bar appears as:
G:\courses\flash\1\EN\course\html\certPopup.html
Browser is IE version 10.0.9200.16540 on all workstations.
Flash version is WIN 11,6,602,180 or higher.
I'm really stumped as to why the URL in the address bar is different on different machines, with the parameters being stripped.

The reason the first works and second doesn't is, that the first one is a URL, the second one is a file path. I have no idea if this might work, but try changing
var printURL = "html/certPopup.html";
to
var printURL = root.loaderInfo.loaderURL.replace(root.loaderInfo.loaderURL.split("/").pop(), ""); + "html/certPopup.html";
But since you are working on an offline project: Why donĀ“t you work with AIR with captive runtime? Would be easier and the possibilities would be much greater?

Related

AS3 - LocalConnection Doesn't Seem to Work

I'm trying to set up communication between three swfs loaded into separate broswer windows (all opened by the initially opened page) using LocalConnection. I'm new to inter-swf communication, and am going by the tutorial found here.
I'm running these from a xampp server for testing.
Essentially, I have 3 swfs. I have one 'master' swf, and two 'slave' swfs. When the master swf is launched, it opens both other swfs in new windows. When a button is clicked in the master, I'm trying to just update some text in one of the slaves. More complicated stuff will happen later, I'm just trying to figure out LocalConnections first.
The code (on the timeline) in 'master.swf':
import flash.net.URLRequest;
import flash.events.Event;
//Used as a flag to open each slave window, one of the first frame, one on the second frame, as using navigateToURL twice in a row doesn't seem to work.
var frameCount = 0;
//This is what I'm attempting to send over the LocalConnection.
var messageText = "it worked!";
var slave1url:URLRequest = new URLRequest("slave1.html");
var slave2url:URLRequest = new URLRequest("slave2.html");
//Creates a one-way connection to communicate with JUST slave1
var slave1OutboundConnection:LocalConnection = new LocalConnection();
this.addEventListener(Event.ENTER_FRAME, Update);
slave1Button.addEventListener(MouseEvent.CLICK, SendMessageToSlave1);
slave1Button.buttonMode = true;
//Send a message to slave1 via the slave1OutboundConnection
function SendMessageToSlave1(e:Event){
slave1OutboundConnection.send("masterToSlave1Connection", "UpdateTextFromCommunication", messageText);
}
function Update(e:Event){
//Open the slave1 page on the first frame, and the slave2 page on the second frame.
if(frameCount == 0){
navigateToURL(slave1url, "_blank");
frameCount++;
} else if (frameCount == 1){
navigateToURL(slave2url, "_blank");
frameCount++;
}
}
In slave1:
var masterInboundConnection:LocalConnection = new LocalConnection();
masterInboundConnection.allowDomain("*");
masterInboundConnection.connect("masterToSlave1Connection");
function UpdateTextFromCommunication(receivedArguments){
displayText.text = receivedArguments;
}
I've also got a little bit of custom javascript in each html page to set page size and position, but I don't think that should matter:
<script>
//Get the width of the user's monitor
var resolutionWidth = window.screen.availWidth;
//Get the height of the user's monitor (minus the height of the task bar)
var resolutionHeight = window.screen.availHeight;
//First screen is 0, second is 1, third is 2, etc.
var screenNumber = 2;
//If this screen is not displayed on the primary monitor, add 40 pixels for the lack of the taskbar on other monitors
if(screenNumber > 0){
resolutionHeight += 40;
}
//Maximize the window
this.resizeTo(resolutionWidth, resolutionHeight);
//Move the window to the appropriate display
this.moveTo(resolutionWidth * screenNumber, 0);
</script>
When I click the button that's supposed to trigger the communication, nothing appears to happen.
I'm running the html pages containing these swfs in IE11 on a localhost xampp server on Windows 7. Swfs made in CS5.5.
In each of the inbound connections, I was missing a single line of code:
masterInboundConnection.client = this;
Now everything is working as expected.

Getting Bitmap from Video decoded with Nestream AppendBytes (AS3)?

I am wondering if someone who has handled NetStream.appendBytes in Flash knows how to get the bitmapData from a decoded video frame? I have already looked at this question but that is from 3 years ago and the more recent comment/answer seems to be gone. In 2014 has anyone managed to turn those bytes into a bitmap? I am working with Flash Player 11.8 and this is not a desktop/AIR app.
In the image below I can do steps 1) and 2) but there's a brick wall at step 3)
The problem is that simply using bitmapdata.draw(video_container); does not work but instead it throws a Policy File error even though I am using a byteArray (from local video file in the same directory as the SWF). No internet is even involved but Flash tells me that "No Policy File granted permission from the server" or such nonsense. I think the error is just a bail-out insteading of straight up saying "You are not allowed to do this.."
I have tried: trying to appease this Crossdomain.xml issue anyway and looking into all known security/domain settings. I came to the conclusion that the error is not the problem but a side effect of the issue.. The issue here being that: Flash Player is aware of the SWF's location and of any files local to it. That's okay when you pass a String as URL etc but when the Netstream data is not local to the SWF domain then it becomes a Policy File issue. Problem is my data is in the Memory not in a folder like the SWF and therefore cannot alllow bitmapData.draw since it cannot "police" an array of bytes, any known fixes for this?... (I can't even say the words I really wanted to use).
What I am trying to achieve: Is to essentially use Netstream as an H.263 or H.264 image decoder in the same way Loader is a JPEG-to-Bitmap decoder or LoadCompressed.. is an MP3-to-PCM decoder. You know, access the raw material (here RGB pixels), apply some effects functions and then send to screen or save to disk.
I know it is a little late, but I think I found a solution for your problem.
So, to avoid the Security sandbox violation #2123 Error, you have just to do like this :
// ...
net_stream.play(null);
net_stream.play('');
// ...
Hope that can help.
I know this question is a couple months old, but I wanted to post the correct answer (because I just had this problem as well and other will too).
Correct answer:
It's a bug that has been open at adobe for almost 2 years
Link to the bug on Adobe
Work Around until the bug gets fixed (I am using this and it works great):
Workaround using Sprite and graphics
To take a snapshot from a video stream we don't need NetStream.appendBytes which inject data into a NetStream object.
For that we can use BitmapData.draw which has some security constraints. That's why in many times we get a flash security error. About that, Adobe said :
"... This method is supported over RTMP in Flash Player 9.0.115.0 and later and in Adobe AIR. You can control access to streams on Flash Media Server in a server-side script. For more information, see the Client.audioSampleAccess and Client.videoSampleAccess properties in Server-Side ActionScript Language Reference for Adobe Flash Media Server. If the source object and (in the case of a Sprite or MovieClip object) all of its child objects do not come from the same domain as the caller, or are not in a content that is accessible to the caller by having called the Security.allowDomain() method, a call to the draw() throws a SecurityError exception. This restriction does not apply to AIR content in the application security sandbox. ...".
For crossdomain file creation and some other security config for AMS server, you can take a look on this post : Crossdomain Video Snapshot - Fixing BitmapData.draw() Security Sandbox Violation.
After allowing our script to get data from our video stream, we can pass to the code.
I wrote a code that play a video stream ( rtmp or http ) and take a snapshot to show it in the stage or save it as a file after applying a pixel effect :
const server:String = null; //'rtmp://localhost/vod'
const stream:String = 'stream'; // 'mp4:big_buck_bunny_480p_h264.mp4';
var nc:NetConnection;
var ns:NetStream;
var video:Video;
const jpg_quality:int = 80;
const px_size:int = 10;
nc = new NetConnection();
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, function(e:AsyncErrorEvent):void{});
nc.addEventListener(NetStatusEvent.NET_STATUS, function(e:NetStatusEvent):void{
if(e.info.code == 'NetConnection.Connect.Success'){
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, function(e:NetStatusEvent):void{});
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, function(e:AsyncErrorEvent):void{});
video = new Video(320, 180);
video.x = video.y = 10;
video.attachNetStream(ns);
addChild(video);
ns.play(stream);
}
})
nc.connect(server);
btn_show.addEventListener(
MouseEvent.CLICK,
function(e:MouseEvent): void{
var bmp:Bitmap = pixelate(video, px_size);
bmp.x = 10;
bmp.y = 220;
addChild(bmp);
}
)
btn_save.addEventListener(
MouseEvent.CLICK,
function(e:MouseEvent): void{
var bmp:Bitmap = pixelate(video, px_size);
var jpg_encoder:JPGEncoder = new JPGEncoder(80);
var jpg_stream:ByteArray = jpg_encoder.encode(bmp.bitmapData);
var file:FileReference = new FileReference();
file.save(jpg_stream, 'snapshot_'+int(ns.time)+'.jpg');
}
)
function pixelate(target:DisplayObject, px_size:uint):Bitmap {
var i:uint, j:uint = 0;
var s:uint = px_size;
var d:DisplayObject = target;
var w:uint = d.width;
var h:uint = d.height;
var bmd_src:BitmapData = new BitmapData(w, h);
bmd_src.draw(d);
var bmd_final:BitmapData = new BitmapData(w, h);
var rec:Rectangle = new Rectangle();
rec.width = rec.height = s;
for (i = 0; i < w; i += s){
for (j = 0; j < h; j += s){
rec.x = i;
rec.y = j;
bmd_final.fillRect(rec, bmd_src.getPixel32(i, j));
}
}
bmd_src.dispose();
bmd_src = null;
return new Bitmap(bmd_final);
}
Of course, this is just a simple example to show the manner to get a snapshot from a video stream, you should adapt and improve it to your needs ...
I hope all that can help you.

How to use httpget on AdobeAIR?

Using some home automation software that allows me to use httpget/httppost to get the status and control the state of devices in my home. I can use it just fine when I'm on my home wifi network (using the internal IP address in the URL), but when I attempt the same outside of my network, nothing happens. I have all ports forwarded properly, because if I post the exact same URL into my browser, it will perform whatever task was indicated.
An example would be:
function LampOn(event:MouseEvent):void{
import flash.net.*;
var url:String = "http://" + ipaddy + "/HomeSeer_REST_API.aspx?function=setdevicebyname&param1=lamp&param2=on";
var request:URLRequest = new URLRequest(url);
var loader:URLLoader = new URLLoader();
loader.load(request);
}
When I use my home IP in the variable 'ipaddy' it works fine, when I use my external IP (in the form username:password#ipaddress:port ) it does nothing.

FileReference.save() is not working stable on browser as3

I would like to use FileReference.save() in 4 different place in a flash game. All 4 methods are the same (copy & paste). Locally, all 4 work perfectly however when I put the swf in browser, facebook actually, only one of them works as expected and the others do not. In Chrome, all 3 have never worked. In Safari, they work sometimes but nondeterministic. What can be the reason? Any idea?
By the way, I compiled with Air 2.5 and Air 3.2 Desktop, I use Flash CS6
private function onScreenShotButtonClicked(e:MouseEvent)
{
mScreenShotButton.removeEventListener(MouseEvent.CLICK, onScreenShotButtonClicked);
var finalBitmapData:BitmapData = new BitmapData(810, 520, true, 0x00000000);
var finalBitmap:Bitmap = new Bitmap(finalBitmapData, PixelSnapping.ALWAYS, false);
finalBitmapData.draw(mParent.root);
var finalData:ByteArray = new ByteArray();
finalData = PNGSave.encode(finalBitmapData);
var tempFileReference:FileReference = new FileReference();
tempFileReference.addEventListener(Event.COMPLETE, onSaveCompleted);
tempFileReference.addEventListener(Event.CANCEL, onSaveCancelled);
tempFileReference.save(finalData, "boombox.png");
}
The common problem is that your method dont't have MouseEvent instance param. May be you call Filereference.save () but you don't have a event argument in function.

flash as3 and external text config file

My goal was to have an external text file config for a client. I didnt want to go through a crazy xml thing, I just wanted it to be simple to change.
I started with a urlLoader, and was able to dynamically generate an object no problem. This is the function which parses and sets the properties of the object.
function onLoaded(e:Event):void//initializes the config
{
var myString = String(e.target.data);
//trace(e.target.data);
//trace(myString);
var propsArray:Array = myString.split("\n");
for (var i = 0; i < propsArray.length; i++){
var thisLine:Array = propsArray[i].split("=");
var thisPropName:String = thisLine[0];
thisPropName = thisPropName.replace(rex,'');
var thisPropValue:String = thisLine[1];
thisPropValue = thisPropValue.replace(rex,'');
trace("thePropName is: " + thisPropName);
trace("thePropValue is: " + thisPropValue);
config[thisPropName] = thisPropValue;
}
}
The text file would just look something like:
gateway = "http://thePathto/theFile.php
toast = sonofabitch
timer = 5000
xSpeed = 5.0
That way, I could just put a little bit of as3 code in, type what things I wanted configured, then all I would have to do was type config.timer and
var myTimer:Timer = new Timer(Number(config.timer));
I think the problem is load order and scope. The config.timer is not created yet, so the timer is unable to access the value of the config.timer.
I'd look at using XML in future projects of this nature, however to answer your question:
I think the problem is load order and scope. The config.timer is not created yet, so the timer is unable to access the value of the config.timer.
Correct, you will need to initialize your Timer within the onLoaded() method, as the data will be received asynchronously and is not available until this happens.
ok not long ago i had created a download manager that uses this exact concept.
The link below will take you straight to the website where you can download the full swf including my source files. also this website is a good place for resources
http://ffiles.com/flash/web_applications_and_data/dynamic_download_manager_3529.html
Below is my loader:
addEventListener(Event.ENTER_FRAME, update);
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.load(new URLRequest("settings.txt"));
myLoader.addEventListener(Event.COMPLETE, onDataLoad);
function onDataLoad(evt:Event)
{
box1.text = evt.target.data.Id_1;
box2.text = evt.target.data.Id_2;
box3.text = evt.target.data.Id_3;
box4.text = evt.target.data.Id_4;
box5.text = evt.target.data.Id_5;
}
Add some dynamic text boxes to stage and name them "box1, box2 ect..."
Now creat your text file:
Id_1=this is what ever you want
&Id_2=this is what ever you want
&Id_3=this is what ever you want
&Id_4=this is what ever you want
&Id_5=this is what ever you want
Hope this helps.