Flash Builder + JSON + ac3corelib = error - json

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!

Related

Accessing JSON array after it has been streamed, Flash as3

I have the following code:
import flash.utils.describeType;
import flash.utils.getQualifiedClassName;
import flash.text.TextField;
stop();
var chartsURL : URLRequest = new URLRequest();
chartsURL.url="http://zagony.net/charts.php"
chartsURL.method=URLRequestMethod.GET;
var streamer:URLLoader=new URLLoader();
streamer.addEventListener(Event.COMPLETE, receive);
streamer.addEventListener(IOErrorEvent.IO_ERROR, missing);
streamer.load(chartsURL);
function receive (event : Event) : void
{
var buttonsCount:int = 0;
var json : String = event.target.data;
var myResults:Object = JSON.parse(json);
//trace(json);
for each(var data:Object in myResults)
{
var listItem:ListItem = new ListItem();
addChild(listItem);
listItem.y = 200 + (buttonsCount * 400);
buttonsCount++;
}
}
function missing (event : Event) : void
{
//trace("broken");
}
It successfully gets the JSON from the URL, but when it goes to add a symbol for each entry in the array, it simply does nothing.
This problem is only worsened by the fact that I'm using Flash 11 export in CS5, and therefore I can't use the built in Test Movie or trace to the console.
If anybody could point out what I'm doing wrong, it would be greatly appreciated. Thanks in advance.

Incorrect calling of external mp3 file

I am getting Error:#2044, so I assumed that my code is wrong in calling the Sound functions but I can't seem to find where I am making the error.
package {
import flash.display.MovieClip;
import flash.media.SoundChannel;
import flash.media.Sound;
import flash.net.URLRequest;
public class Tile extends MovieClip{
public function GetAndSwitchKey():String {
//Some Code//
//Create sounds
//------------> Start here
var bSound:Sound = new Sound();
var bReq:URLRequest = new URLRequest("B.mp3");
var oSound:Sound = new Sound();
var oReq:URLRequest = new URLRequest("O.mp3");
var mSound:Sound = new Sound();
var mReq:URLRequest = new URLRequest("M.mp3");
//Load sounds
bSound.load(bReq);
oSound.load(oReq);
mSound.load(mReq);
//<-------- End here
//Some code//
switch (temp) {
case "B": bSound.play(); break;
case "O": oSound.play(); break;
case "M": mSound.play(); break;
}
//Some code//
}
}
}
The way I added the files is by placing them inside the same file as the Action script 3 file. I also then changed them in the propperties to be exportable for action script. But as far as I am aware I don't have to specify the directory since a copy is made in the SWF.
Replacing the code indicated between the "start here" and "end here". This will resolve the error. And will call the sound file properly.
var mySoundHolder = new mySound();

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

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.

Error #1009: Cannot access a property or method of a null object reference

Working on this Flash AS3 application and I am keep getting this error when I try to make an imgLoader clickable.
The imgLoader is a dynamic loader which will load an image from XML file and its created using ActionScript.
This is the full error I get:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at apptest_fla::MainTimeline/frame1()[apptest_fla.MainTimeline::frame1:65]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
and this is the code for making the imgLoader clickable:
imgLoader.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
anyone knows why this is happening?
EDIT
This is my entire code:
stop();
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Sprite;
import flash.filters.DropShadowFilter;
var xmlLoader11:URLLoader;
var xml11:XML;
var uRequest11 = new URLRequest("my.xml");
xmlLoader11 = new URLLoader(uRequest11);
xmlLoader11.addEventListener(Event.COMPLETE, onXMLLoad11);
var imgLoader11:Loader;
var nameLoader11:Loader;
var myString11:String = 'loading';
function onXMLLoad11(e:Event) {
xml11 = new XML(e.target.data);
imgLoader11 = new Loader();
imgLoader11.contentLoaderInfo.addEventListener(Event.COMPLETE, onImgLoaded11);
imgLoader11.load(new URLRequest(xml11.Data.Image.text()[0]));
Nametxt11.text = "" + xml11.Data.Name.text()[0];
}
function onImgLoaded11(e:Event) {
addChild(imgLoader11);
imgLoader11.height = 300;
imgLoader11.width = 300;
var bitmapContent11:Bitmap = Bitmap( e.target.content );
bitmapContent11.smoothing = true;
addChild( bitmapContent11 );
bitmapContent11.height = 150;
bitmapContent11.width = 150;
bitmapContent11.y = 65;
bitmapContent11.x = 85;
}
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
Does it break when this is called:
imgLoader.addEventListener(MouseEvent.CLICK, doSomething);
or when this is called:
nextFrame()
In the first case, imgLoader is null. In the second case, something you're trying to acess fields or methods of right after nextFrame() is called is null.
EDIT:
Try moving this:
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
}
to the bottom of onXMLLoad11().
function onXMLLoad11(e:Event) {
xml11 = new XML(e.target.data);
imgLoader11 = new Loader();
imgLoader11.contentLoaderInfo.addEventListener(Event.COMPLETE, onImgLoaded11);
imgLoader11.load(new URLRequest(xml11.Data.Image.text()[0]));
Nametxt11.text = "" + xml11.Data.Name.text()[0];
imgLoader11.addEventListener(MouseEvent.CLICK, doSomething);
function doSomething(event:MouseEvent){
nextFrame()
}
}

AS3 Form Inquiry

I am relatively new to AS3. I am having a few code issues at the moment i am hoping for some advice on this forum.
Basically, i am creating a form for my website. I have one combobox and I want The user enter their email address and password into the fields.
Then click on the submit button to sign in and to validate what they entered is correct. When i run my code in real-time i get an error
1120: Access of undefined property status_Txt. I dont know what status_Txt means.
I copied a large section of this code from a tutorial i read. My code is below: Can someone please tell me how i can resolve this problem.
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.MouseEvent;
import fl.data.DataProvider;
import flash.events.Event;
//Building the variables
var phpVars:URLVariables = new URLVariables();
//Requesting the php file
var phpFileRequest:URLRequest = new URLRequest("http://www.example.com");
phpFileRequest.method = URLRequestMethod.POST;
phpFileRequest.data = phpVars;
//Building the loader
var phpLoader:URLLoader = new URLLoader();
phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
phpLoader.addEventListener(Event.COMPLETE, showResult);
//Variables ready for processing
phpVars.email = txt_input.text;
phpVars.p_swd = pass.text;
phpLoader.load(phpFileRequest);
btn_one.addEventListener(MouseEvent.CLICK, btnHandler);
function btnHandler(event:MouseEvent):void{
trace("Login success");
}
//Validate form fileds
function showResult(event:Event):void{
status_Txt.text = "" + event.target.data.systemResult;
trace(event.target.data.systemResult);
}
var cbox:Array = new Array();
boy[0] = "Male";
girl[1] = "Female";
c_one.dataProvider = new DataProvider(cbox);
c_one.addEventListener(Event.CHANGE, dataHandler);
function dataHandler(e:Event):void{
trace(e.target.value);
}
}
You're attempting to access an object that doesn't exist. status_Txt is being referenced in:
function showResult(event:Event):void{
status_Txt.text = "" + event.target.data.systemResult; //Either remove this or add a textfield to the stage with the instance name status_Txt
trace(event.target.data.systemResult);
}