The variable that read from txtfile can't be assigned using AS3 - actionscript-3

I am trying to read 3 variables from txtfile using this code :
stop();
import flash.system.SecurityDomain;
import flash.system.Security;
import flash.text.Font;
import flashx.textLayout.formats.Direction;
import fl.text.TLFTextField;
import flashx.textLayout.factory.StringTextLineFactory;
//---------------------
var myTextLoader:URLLoader = new URLLoader();
myTextLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
var ip:String;
var port:String;
var margin:Number;
function onLoaded(e:Event):void {
ip=e.target.data.ip;
port=e.target.data.port;
margin=e.target.data.margin;
trace(e.target.data.ip);
trace(e.target.data.port);
gotoAndPlay(2);
}
myTextLoader.load(new URLRequest("example.txt"));
//---------------------
I put this code in the first frame in frame 2 i use the variables (ip,port,margin) but they are null!!!why ?
frame 2 action code:
var request:URLRequest = new URLRequest(ip+":"+port+"/Default.aspx?EndStation=22&&direction=right&&lineid=1&&command=all&&");
The output error:
/Default.aspx?EndStation=22&&direction=right&&lineid=1&&command=all&&nocache=1412331762086'
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: http://localhost
:46049
I use trace and the variables is read by my code .
Best regards

Try adding "http://" in front of your request url string.

Related

Actionscript Firebase POSTing, Error #2032

I am trying to POST to my firebase account, but I can't seem to figure out why it's not letting me. I can switch the POST to a GET and trace out the data I'm trying to get, but when I POST I get en error.
Code:
package
{
import flash.display.Loader;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import flash.net.navigateToURL;
import flash.net.URLLoaderDataFormat;
//import flash.system.Security;
/**
* ...
* #author M
*/
public class FireBaseConnector
{
public function FireBaseConnector()
{
//Security.loadPolicyFile("https://demo.firebaseio-demo.com/crossdomain.xml");
trace("trying to post");
var url:String = 'https://[myURL].firebaseio.com/userData.json';
var req:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
variables.name = "alan"
req.data = variables;
req.method = URLRequestMethod.POST;
var l:URLLoader = new URLLoader()
//l.dataFormat = URLLoaderDataFormat.TEXT;
l.addEventListener(IOErrorEvent.IO_ERROR, onError);
l.addEventListener(Event.COMPLETE, handleResults);
l.load(req);
}
public function onError(e:IOErrorEvent):void {
trace("Error! " + e.text);
}
public function handleResults(e:Event):void {
trace("response" + e.target.data as String);
}
}
}
My output is:
[Starting debug session with FDB]
running
trying to post
Error! Error #2032: Stream Error. URL: https://resplendent-fire-2464.firebaseio.com/userData/.json
closing time!
closing time!
If i switch to GET my output is:
[Starting debug session with FDB]
running
trying to post
response{"dave":{"id":"678","name":"dave"},"mike":{"name":"mike"},"miles":{"id":"456","name":"miles"}}
closing time!
closing time!
That tells me I have the url right, but I have some permissions problem or something when trying to post. Maybe I have the variables sending improperly? I've made sure my Flash debugger is on the accepted app list in my Firewall.
I'm running Windows 10 and FlashDevelop JRE 1.6 Flex 4.6 Air 18
To send a POST request to the Firebase REST API you need to send the data JSON encoded:
var urlVars:Object = new Object();
urlVars.name = nameTxt.text;
urlVars.lastname = lastNameTxt.text;
var request:URLRequest = new URLRequest(FIREBASEURL);
request.data = JSON.stringify(urlVars);
request.method = URLRequestMethod.POST;
var firebaseLoader:URLLoader = new URLLoader();
firebaseLoader.addEventListener(flash.events.Event.COMPLETE, function():void
{
trace(firebaseLoader.data);
});
firebaseLoader.load(request);
I try this code can work
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
var urlVars:Object = new Object();
urlVars.name = "111111";
var url:URLLoader=new URLLoader();
var hdr:URLRequestHeader = new URLRequestHeader("Content-type", "application/json");
var req:URLRequest = new URLRequest( "https://[myURL].firebaseio.com/userData.json" );
req.method = URLRequestMethod.POST;
req.data = JSON.stringify(urlVars);
url.load(req);
url.addEventListener(Event.COMPLETE,urlCompelte)
function urlCompelte(e:Event){
trace(e.target.data);//{"name":"-Ka6PGZc_hY-sfJJqeVS"}
}

AdobeFlashCS6 Actionscript3 JSON: Exported SWF and HTML banner don't show JSON information

I have a .swf banner that in adobe FlashCS6 plays fine, but when I export it ( .swf and .html) the banner looses JSON information taken from online JSON file.
What am I doing wrong?
ActionScript Code:
play();
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
var _jsonPath:String = yourURL;
function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest();
request.url = _jsonPath;
loader.addEventListener(Event.COMPLETE, onLoaderComplete);
loader.load(request);
}
init();
function onLoaderComplete(e:Event):void
{
var loader:URLLoader = URLLoader(e.target);
var jsonObject:Object = JSON.parse(loader.data);
//JsonMan.decode(s:String):Object
trace("loader.data: " + loader.data);
trace(jsonObject[3].object.bets[0].title);
if(i<10){
country1.text = String(jsonObject[i].object.bets[0].title).toUpperCase();
country2.text = String(jsonObject[i].object.bets[2].title).toUpperCase();
country1_odds.htmlText = String("<b>"+ jsonObject[i].object.bets[0].odds + "</b>");
country2_odds.htmlText = String("<b>"+jsonObject[i].object.bets[2].odds + "</b>");
x_odds.htmlText = String("<b>"+jsonObject[i].object.bets[1].odds + "</b>");
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'-'+dd+'-'+yyyy;
trace(today);
obj_date.htmlText = String("<b>" + jsonObject[i].object.date + "</b>");
i++;
if(i==9){
i=0;
}
}
}
Edit:
In Chrome console it says:
Failed to load resource: net::ERR_NAME_NOT_RESOLVED cloudssl.my.phpcloud.com/super/contentScript.js 2.
Failed to load resource: the server responded with a status of 404 (Not Found) api.topsport.lt/crossdomain.xml.
GET api.topsport.lt/crossdomain.xml 404 (Not Found) crossdomain.xml:1
In output I receive this text:
`TypeError: Error #1010: A term is undefined and has no properties.`
`at TOPSPORT2_fla::MainTimeline/onLoaderComplete()`
`at flash.events::EventDispatcher/dispatchEventFunction()`
`at flash.events::EventDispatcher/dispatchEvent()`
`at flash.net::URLLoader/onComplete()`
`TypeError: Error #1010: A term is undefined and has no properties.`
`at TOPSPORT2_fla::MainTimeline/onLoaderComplete()`
`at flash.events::EventDispatcher/dispatchEventFunction()`
`at flash.events::EventDispatcher/dispatchEvent()`
`at flash.net::URLLoader/onComplete()`
Add listener for SecurityErrorEvent:
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
It will give you an error because you do not have a crossdomain policy file. Search Google for it - it's a simple xml file that you put on the root of your server. It helps Flash know that it can load resources from that location.
If anyone gets into a situation like this, always remember to clear the browser's catche, or test it on other browsers. It helped in my condition! The code was working all along.

try catch issues actionscript3 IOErrorEvent

This is image share app written in as3. in my ftp there is a file "/Images" and images are inside of that. names are 1.jpg 2.jpg 3.jpg until 21.jpg .(21 images inside of folder). as you can see there are 2 variable totalImages and imageNumber. I entered totalImages = 100.
when I click next button its going next page(next image. Starting 1.jpg). But when it comes image 21(last image),if I click next button i cannot pass image 22.(there is no 22.jpg).And I take this error on Output on Flash. Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed. I want to use try catch method and see error inside of swf. but I dont know where i put try and catch in the code. Thank you in advance
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
//*****************CREATING VARIABLES*****************************//
//the array has all picture labels
//var myGlow:GlowFilter = new GlowFilter(0xffffff,1,10,10,255);// saving the glow
//var myShadow:DropShadowFilter = new DropShadowFilter(6);// saving the shadow to be applied later
var totalImages=100;
var imageNumber=1;
var myLoader:Loader = new Loader();
//************LOADING IMAGES TO STAGE********************//
//elearningau.com/nondynamic/
var myRequest:URLRequest = new URLRequest("http://www.elearningau.com/nondynamic/Images/"+imageNumber+".JPG");
myLoader.load(myRequest);
addChildAt(myLoader,1);// will be added under the buttons layer but over the texture
//************CENTERING THE PICS****************//
myLoader.contentLoaderInfo.addEventListener(Event.INIT, getImageInfo);
function getImageInfo(event:Event){
myLoader.width = 485;
myLoader.height = 360;
var imgX=(stage.stageWidth- myLoader.width)/(-1)*(1/25);
var imgY=(stage.stageHeight- myLoader.height)/2;
myLoader.x=imgX;
myLoader.y = imgY;// lines 37,38,39 & 40 are centering the loader formulae
//myLoader.filters = [myGlow, myShadow];// adding a white color glow / grey shadow
//var myTween:Tween = new Tween(myLoader, "alpha", None.easeNone, 0,1,2,true);//apply fade in
}
//**************GOING TO NEXT IMAGE********************************//
rightButton.addEventListener(MouseEvent.CLICK, nextImage);
function nextImage(event:MouseEvent){
if(imageNumber<totalImages)
{
imageNumber++;
}
else (imageNumber=1);
reload();
}
//**************GOING TO PREVIOUS IMAGE********************************//
leftButton.addEventListener(MouseEvent.CLICK, previousImage);
function previousImage(event:MouseEvent){
if(imageNumber>1)
{
imageNumber--;
}
else (imageNumber=totalImages);
reload();
}
//*****************RELOADING****************************//
//elearningau.com/nondynamic/
function reload(){
removeChild(myLoader);
myRequest= new URLRequest("http://www.elearningau.com/nondynamic/Images/"+imageNumber+".JPG");
myLoader.load(myRequest);
addChildAt(myLoader,1);// will be added under the buttons layer but over the texture
}
You are missing the error handlers from your loader:
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
function onError(e:IOErrorEvent):void {}
try/catch does not work with asynchronous events, and load is asynchronous.

how to embed pdf file in flash based application (IOS and android)

I’m creating application for android and IOS using FLASH CS5.5
I want to open pdf file when I click on the button. I try to use this code but is not working
package
{
import flash.html.HTMLLoader;
import flash.net.URLRequest;
import flash.display.NativeWindowInitOptions;
import flash.display.NativeWindowSystemChrome;
import flash.display.NativeWindowType;
import flash.display.NativeWindow;
import flash.events.Event;
import flash.display.SimpleButton;
public class bpdf extends SimpleButton
{
public function bpdf()
{
// constructor code
var htm:HTMLLoader= new HTMLLoader();
htm.load(new URLRequest("test.pdf"));
var init:NativeWindowInitOptions= new NativeWindowInitOptions();
init.systemChrome = NativeWindowSystemChrome.STANDARD;
init.type = NativeWindowType.NORMAL;
var win:NativeWindow = new NativeWindow(init);
win.stage.addChild(htm);
win.width = stage.stageWidth;
win.height = stage.stageHeight;
win.activate();
htm.width = win.width;
htm.height = win.height;
win.addEventListener(Event.CLOSE, onCloseEvent);
}
function onCloseEvent(e:Event)
{
trace("window closed");
}
}
}
after publishing with “PLYER: AIR FOR ANDROID” then I got these error message in output
[SWF] link2.swf - 2907 bytes after decompression
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at bpdf()[C:\Users\HP\Desktop\PDF Link\Link_2\bpdf.as:30]
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
I also convert my file in APK and check in my android device but same problem when I click on the button, nothing happened
I make my APK file without include pdf and with include pdf
Include my pdf file using this way:: Publish setting > PLAYER: AIR FOR ANDROID – setting > Included files: test.pdf
Try with this
If you want to open pdf use StageWebView instead of HTMLLoader class. Like this
protected function loadPDF(event:MouseEvent):void {
var file:String = "Lorem_Ipsum.pdf";
var yOffset:Number = 40;
var stageWebView:StageWebView = new StageWebView();
stageWebView.stage = stage;
stageWebView.viewPort = new Rectangle(0, yOffset, 500, 500 - yOffset);
var pdf:File = File.applicationStorageDirectory.resolvePath(file);
stageWebView.loadURL(pdf.nativePath);
}
source : more details
Also look at stack overflow display-local-pdf

Flash Builder + JSON + ac3corelib = error

I'm trying to receive an array using URLLoader. I included ac3corelib to my project and declared JSON library: "import com.adobe.serialization.json.JSON;" However, when I use "JSON.decode(e.target.data)" I get an error "Access of undefined property JSON".
Here is the code:
import com.adobe.serialization.json.JSON;
private function getContacts():void {
var contacts:URLLoader = new URLLoader();
contacts.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
var con:Object = JSON.decode(e.target.data);
}
contacts.load(new URLRequest("http://domain.com/cmd.php?action=contacts"));
}
Thanks in advance!
Use the below code
var con:Object = com.adobe.serialization.json.JSON.decode(e.target.data);
instead of
var con:Object = JSON.decode(e.target.data);
Dont forget to import below package
import com.adobe.serialization.json.JSON;
its working good for me!