Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

need some help with arrays

[ Edited ]

Alright, so far I can get my URL Requests perfectly, display the page with css formatting, even the formatting on the page all normally, now what I'm trying to do is to pull data from an API which I'm making into an array in the app.


function loaderCompleteHandler(evt:Event):void{
        stField.htmlText = evt.target.data;
	var stArr:Array = evt.target.data.MyApi.split(",");
}

That is the code I"m using to get the data into my array, and it's the 3rd or 4th iteration of the code that I've done, the simplest too....


It pulls an array from example.php which has the following text:

stbbAPI=1,yPUz,1,1,<img src="imagelocation">,http://tensioncore.com


I've tried using trace(stArr[0]); but it doesn't display anything


Now It doesn't seem to be pulling any data (however the stField - which shows the htmlText works fine)...I make a few if statements after this and they act as if there isn't anything there....and I try to display some of the info from the "array" to the display yet nothing shows...


Any help?

CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: need some help with arrays

You can do a trace on the array like:

 

trace( 'stArr=' + stArr.toString() );

 

Not certain the the MyApi field is, but if the text going to the stField is correct, and it is plain text and not HTML, then

 

var stArr:Array = String( evt.target.data ).split( ',' );

 

should work fine

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: need some help with arrays

hey tensioncore,

 

im not entirely sure this part is intended to do:

 

evt.target.data.MyApi

 

The data that comes in can either be in text, variable, or binary format. Are you changing the format? if not the default is text which explains why the .htmlText is working fine. the problems lies in how you are setting up your array. what is the exact output of the page you are requesting?

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: need some help with arrays

Output of the page is:
stbbAPI=1,yPUz,1,1,,http://tensioncore.com
CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: need some help with arrays

In that case what john stated should work. If u take out the MyApi portion it will receive the text and split it into an array fine.
J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: need some help with arrays

Sorry I made a mistake typing my code out there....they should both be stbbapi just like in the page output....

I had just seen somewhere that you could use the evt.target.data.stbbapi just like its a subclass defined by the stbbapi= * on the page output...sort of like an associative array.
CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: need some help with arrays

ah ok i get what you are doing there. in that case what you need to do is convert the data you are retreiving into a URLVariables object like so:

 

 

function loaderCompleteHandler(evt:Event):void{
        stField.htmlText = evt.target.data;
        var variables:URLVariables = new URLVariables(evt.target.data);
	var stArr:Array = variables.stbbAPI.split(",");
	trace(stArr);
}

 

that should do the trick. lemme know if thats what you are looking for. good luck!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: need some help with arrays

So I tried that, and still no output with anything....If statements still do nothing....I'm lost
CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: need some help with arrays

hey tensioncore,

 

run this exact code below and see what your results are. i ran it here and everything outputs fine as expected. the page is real and live and exactly what you wrote is the output. check the trace and see what the results are:

 

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	import flash.text.TextFieldAutoSize;
	
	import qnx.ui.buttons.LabelButton;
	import qnx.ui.text.Label;
	
	[SWF(width="1024", height="600", backgroundColor="#CCCCCC", frameRate="30")]
	public class URLLoaderTest extends Sprite
	{
		private var loader:URLLoader;
		private var request:URLRequest;
		private var myTextField:Label;
		private var myBtn:LabelButton;
	
		public function URLLoaderTest()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			request = new URLRequest("http://www.rabcore.com/workshop/playbook/variableTest.php");
			
			loader = new URLLoader();
			loader.load(request);
			loader.addEventListener(Event.COMPLETE, handleData);
			
			myTextField = new Label();
			myTextField.setSize(100, 50);
			myTextField.setPosition(10,10);
			myTextField.textField.autoSize = TextFieldAutoSize.LEFT;
			
			myBtn = new LabelButton();
			myBtn.label = "This will already be here";
			myBtn.setSize(200, 70);
			myBtn.setPosition(10, 50);
			
			addChild(myTextField);
			addChild(myBtn);

		}
		private function handleData(e:Event):void
		{
			var variables:URLVariables = new URLVariables(e.target.data);
			
			var myArray:Array = variables.stbbAPI.split(",");
			
			trace(myArray);
		}
	}
}

 

good luck!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: need some help with arrays

...So it must be that I am using Flash Burrito...but so...er..., I seem to always get an error when using super();
...and when a function doesn't declare :void it never works....and well, I'm not getting any output with the app..
But on a lighter Note, I DID get MY original code to work, it seems that for some reason, I can't use the data from the URL Request twice...because when I removed the stField.htmlText from the code...and didn't touch anything else...than magically the trace(stArr); worked fine! and so did the if statements.
CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting