how to GET/load url invisbly in Actionscript? - actionscript

how can I load url or send GET to a url via actionscript ? I want to create an invisble flash app that can help with analytics.
I am a inexpperienced with actionscript and flash. what good guides are there to gett staarted ? as2 or 3 ? diffiernce ?

IN AS3, this is generally how you'd do it:
var req:URLRequest("http://your_request");
var loader:URLLoader = new URLLoader ();
loader.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(req);
private function onLoadComplete(ev:Event):void
{
var result:String = ev.target.data;
}
Look up AS3 URLLoader on google to get tons of more info on how to use this.

Related

Security Error when trying to load ByteArray from mediaPromise

in a mobile application i need to send an image which the user either took with the camera or picked from a cameraroll.
I am using the starling framework and feathersUI ( although i think this does not matter to problem )
When the mediapromise is loaded using loadFilePromise i use the following code to deal with the image data:
_mediaLoader = new Loader()
//loading the filePromise from CameraRoll
_mediaLoader.loadFilePromise(_mediaPromise);
_mediaLoader.contentLoaderInfo.addEventListener(starling.events.Event.COMPLETE, onLoadImageComplete);
private function onLoadImageComplete(event:flash.events.Event=null):void {
//creating the starling texture to display the image inside the application
var texture:Texture = Texture.fromBitmapData(Bitmap(_mediaLoader.content).bitmapData, false, false, 1);
//now trying to load the content into a bytearray to send to the server later
var bytes:ByteArray=_mediaLoader.contentLoaderInfo.bytes;
}
the last line of code results in a Security error:
Error #2044: Unhandled SecurityErrorEvent:. text=Error #2121: Security sandbox violation: app:/myapp.swf: http://adobe.com/apollo/[[DYNAMIC]]/1 cannot access . This may be worked around by calling Security.allowDomain.
I tried
Security.allowDomain("*")
as a test
but then i get:
SecurityError: Error #3207: Application-sandbox content cannot access this feature.
As a workaround i write my own png ByteArray inside the Application from the loaders BitmapData using Adobes PNGEncoder Class:
var ba:ByteArray=PNGEncoder.encode(Bitmap(_mediaLoader.content).bitmapData)
But this takes a significant amount of time ...
I also tried the FileReference to load the image but
_mediaPromise.file
and
_mediaPromise.relativePath
are both null.
What am I doing wrong? Or is this a known problem ?
Thanks!
Hello I have found a solution based on a post about the processing of exif data mentioned here: http://blogs.adobe.com/cantrell/archives/2011/10/parsing-exif-data-from-images-on-mobile-devices.html
the crucial code
private function handleMedia(event:MediaEvent):void{
_mediaPromise=event.data as MediaPromise;
_imageBytes=new ByteArray()
var mediaDispatcher:IEventDispatcher = _mediaPromise.open() as IEventDispatcher;
mediaDispatcher.addEventListener(ProgressEvent.PROGRESS, onMediaPromiseProgress);
mediaDispatcher.addEventListener(flash.events.Event.COMPLETE, onMediaPromiseComplete);
};
private function onMediaPromiseProgress(e:ProgressEvent):void{
var input:IDataInput = e.target as IDataInput;
input.readBytes(_imageBytes, _imageBytes.length, input.bytesAvailable);
};
private function onMediaPromiseComplete(e:flash.events.Event):void{
_mediaLoader = new Loader();
_mediaLoader.loadBytes(_imageBytes)
};
works like a charm for me on ipad and iphone.

AS3 iOS : Loading external swf

I'm trying to load a swf in another using AIR3.6.
I duplicated the code I found here http://blogs.adobe.com/airodynamics/2012/11/09/packaging-and-loading-multiple-swfs-in-air-apps-on-ios/ but in vain. It does'nt work.
So I think I didn't understand part of the procedure.
That what I have done :
• I have a first fla I can correctly publish for iOS.
• In this fla I have this code :
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("test.swf");
var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.load(mRequest);
function onCompleteHandler(loadEvent:Event)
{
addChild(loadEvent.currentTarget.content);
}
• In the publish settings I went to the General tab and I included my second swf : test.swf
• The second swf (test.swf). I published it with AIR 3.6 for iOS.
It has no actionscript at all. There is only a green shape in it.
• When I test my first fla, the second one is correctly loaded.
• When I publish it in my iPad, the second swf is NOT loaded.
Can someone tells me where I was wrong ?
Thanks.
All right, 10 seconds after publishing my question, I found my solution.
I only forgot to put the _lc:LoaderContext in the mLoader.load().
So here is it :
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("test.swf");
var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.load(mRequest, _lc);
function onCompleteHandler(loadEvent:Event)
{
addChild(loadEvent.currentTarget.content);
}
Note to moderators : Not sure this will be helpfull for anyone, but I don't know how to delete a post.

Firefox - Accessing add-on objects in web page script

referring to recent Info provided by firefox that it is possible to access extension object in content safely. https://blog.mozilla.org/addons/2012/08/20/exposing-objects-to-content-safely/
I am trying to do this in the hello world extension downloaded from Firefox website.
var sharedObject = { foo : "Hello!" };
window.wrappedJSObject.sharedObject = sharedObject;
and in my webpage JS I have
alert(window.sharedObject.foo);
But it says window.sharedObject undefined. Any clues ? I want to do it safely too but first I intend to get it working.
Thanks,
It's the contentWindow you want to inject your object
var sharedObject = { foo : "Hello!" };
contentWindow.wrappedJSObject.sharedObject = sharedObject;
Keep in mind that without the __exposedProps__ property, foo will be undefined for the webpage code.

Flash Media Server & AS3: Publishing works, recording doesn't

I'm currently having an issue with FMS4 developer edition on both Linux (x64) and Windows XP (x86).
When I stream a webcam using ns.publish("foobar", "live") I can watch the live stream on another client, however when i use ns.publish("foobar", "record"); neither broadcasting nor recording works.
Using the "live" parameter the client appears in the log files and in the administration console as "publishing", using "record" the client appears as "idle".
Is there anything I need to configure besides LIVE_DIR in fms.ini?
Is this a restriction in the developer edition?
Is there something else I'm missing?
Here is the relevant part of the code (condensed):
var camLive:Camera = Camera.getCamera();
var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
var ns:NetStream;
nc.connect("rtmp://192.168.1.63/live/");
function netStatusHandler(event:NetStatusEvent):void {
if (event.info.code == "NetConnection.Connect.Success") {
ns = new NetStream(nc);
ns.attachCamera(camLive);
ns.publish("foobar", "record");
}
}
Thanks in advance!
Fabian
The problem is the live application. You can create an empty folder inside "applications", call it "test", then stream to "rtmp://192.168.1.63/test" with parameter "record". According to forums.adobe.com/thread/827134?tstart=0

Flash Media Server calling a page that returns JSON data

I am very new to Flash development.
I have an asp.net mvc site that has a controller action that returns JSON.
I have a Flash Media Server setup that needs to call that controller action every 15 minutes to get the current schedule. I can get the FMS to call the site (and every 15 minutes no problem) and I am getting the JSON right now as a string, but I need to parse it from the string to objects, in order to use the data returned.
Any pointers or ideas would be very welcomed.
Mike Chambers has an AS3 library on github (https://github.com/mikechambers/as3corelib). One of the libraries is for JSON serialization and parsing. Here's his example of it in a Flex MXML document, but would be the same in AS3 ( you basically get the JSON data, then call JSON.decode() on it to get an Array. ):
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
layout="absolute"
creationComplete="service.send()" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import com.adobe.serialization.json.JSON;
private function onJSONLoad(event:ResultEvent):void
{
var rawData:String = String(event.result);
var arr:Array = (JSON.decode(rawData) as Array);
var dp:ArrayCollection = new ArrayCollection(arr);
grid.dataProvider = dp;
}
]]>
</mx:Script>
<mx:HTTPService
id="service"
resultFormat="text"
url="http://weblogs.macromedia.com/mesh/mashedpotato.json"
result="onJSONLoad(event)" />
<mx:DataGrid id="grid" right="10" left="10" top="10" bottom="10">
<mx:columns>
<mx:DataGridColumn headerText="Service" dataField="src"/>
<mx:DataGridColumn headerText="Title" dataField="title"/>
</mx:columns>
</mx:DataGrid>
I guess you are using a webservice call from FMS to get the data. In Actionscript 1, I think you should be able to use eval() to get an object that you can then query.
var callback = mWebService.NewGuid();
mWebService.onResult = function(resultString){
var resultObject = eval(resultString);
trace(resultObject.mProperty1);
}

Resources