-
1. Re: as3 xml trouble
CaioToOn! Oct 10, 2009 5:26 AM (in response to Kristtee)Hi, Kristee.
There is three mistake:
1st) You're duplicating the "loader" and "request" variables at
// load text var loader:URLLoader = new URLLoader(); var request:URLRequest = new URLRequest("lorem.txt"); loader.load(request); loader.addEventListener(Event.COMPLETE, loadcomplete); function loadcomplete(event:Event) { // move loaded text to text field myTxt.text = loader.data; // Set myTxt as target for scroll bar. mySb.scrollTarget = myTxt; }You need a different variable name, so, change it to "textLoader" and "textRequest", for example, in all the 6 occurrences.
2nd) The correct variable name is "dataXML", not "teamXML".
var myDP:DataProvider = new DataProvider(teamXML);
3rd) In your XML, when closing the root node <data>, you misstyped it to </date>.
I hope this help.
Regards,
CaioToOn!
-
2. Re: as3 xml trouble
Kristtee Oct 11, 2009 7:57 PM (in response to CaioToOn!)Hi
Thank you - CaioToOn. You are The Man. As you have helped me, i did all the corrections and it is just cool. There is one more question. I wonder whether it is possible to bind the image and textfield data from the same xml file. Presently it is not from the xml data. Can you guide me through..Please. Please.
I really appreciate your time. Thank you again.
regards
Kristtee
-
myApp.zip 248.0 K
-
-
3. Re: as3 xml trouble
Saransoft84 Oct 12, 2009 1:45 AM (in response to Kristtee)Hi,
Try this code:
The data from img and the desc from the XML
var img_name:Array = new Array();
var desc:Array = new Array();
for (var i1:int=0; i1<dataXML.item.length(); i1++) {
img_name.push(dataXML.item.img[i1]);
desc.push(dataXML.item.desc[i1]);
}
trace(img_name+":img_name");
trace(desc+":desc");
Saransoft
-
4. Re: as3 xml trouble
Kristtee Oct 12, 2009 2:24 AM (in response to Saransoft84)hello Saransoft
first of all i thank you so much. yet as i am too new to this..i try to use the code you have given me. but since i did not know how to use - where to put it, i have messed the whole thing up. truly sorry. can you help me please.
Thank you
kristttee
-
5. Re: as3 xml trouble
Saransoft84 Oct 12, 2009 3:01 AM (in response to Kristtee)Hi Kristtee,
It simple ya.
Here is code:
import fl.containers.UILoader;
import flash.net.*;
import fl.controls.UIScrollBar;
import flash.events.*;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.data.DataProvider;
var img_name:Array = new Array();
var desc:Array = new Array();
var request:URLRequest = new URLRequest("datas.xml");
var loader:URLLoader = new URLLoader();
loader.load(request);
loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
function loaderCompleteHandler(event:Event):void {
var dataXML:XML = new XML(loader.data);
var nameCol:DataGridColumn = new DataGridColumn("cate");
nameCol.headerText = "cztegory";
nameCol.width = 180;
var avgCol:DataGridColumn = new DataGridColumn("txt");
avgCol.headerText = "Head Line";
avgCol.width = 400;
for (var i1:int=0; i1<dataXML.item.length(); i1++) {
img_name.push(dataXML.item.img[i1]);
desc.push(dataXML.item.desc[i1]);
}
var myDP:DataProvider = new DataProvider(dataXML);
aDg.columns = [nameCol, avgCol];
aDg.width = 580;
aDg.height = 180;
aDg.dataProvider = myDP;
//aDg.rowCount = aDg.length;
var myTxt:TextField = new TextField();
myTxt.border = true;
myTxt.defaultTextFormat;
myTxt.wordWrap = true;
myTxt.width = 235;
myTxt.height = 150;
myTxt.x = 340;
myTxt.y = 10;
var mySb:UIScrollBar = new UIScrollBar();
mySb.direction = "vertical";
// Size it to match the text field.
mySb.setSize(myTxt.width, myTxt.height);
// Move it immediately below the text field.
//mySb.move(myTxt.x, myTxt.height + myTxt.x);
mySb.move(myTxt.width + myTxt.x, myTxt.y);
// put them on the Stage
addChild(myTxt);
addChild(mySb);
// load text
/*var txtloader:URLLoader = new URLLoader();
var txtrequest:URLRequest = new URLRequest("lorem.txt");
txtloader.load(txtrequest);
txtloader.addEventListener(Event.COMPLETE, loadcomplete);
function loadcomplete(event:Event) {
// move loaded text to text field
myTxt.text = txtloader.data;
// Set myTxt as target for scroll bar.
mySb.scrollTarget = myTxt;
}*/
trace(img_name+":img_name");
trace(desc+":desc");
myTxt.text = desc[0];
// Set myTxt as target for scroll bar.
mySb.scrollTarget = myTxt;
var aLoader:UILoader = new UILoader();
aLoader.scaleContent = false;
aLoader.x = 10;
aLoader.y = 10;
aLoader.width = 320;
aLoader.height = 150;
aLoader.source = img_name[0];//"images/flower.jpg";
addChild(aLoader);
aLoader.addEventListener(Event.COMPLETE, competeHandler);
function competeHandler(event:Event) {
trace("Bites loader: " + aLoader.bytesLoaded);
}
}
Copy all this code and paste in urs
Saransoft
-
6. Re: as3 xml trouble
Kristtee Oct 13, 2009 9:53 PM (in response to Saransoft84)hello Saransoft
thank you so much. I did as you have suggested. coppied all the code replacing my messed up ones. then i test it. woops..the image and textfield data just stays the same. when i try to selected different item from the datagrid, the image and the data do not change. what i try to do is to build similar to Spry Products Demo. Sure it must be too easy for you. Please help me.
Thank you
regards
Kristtee
-
7. Re: as3 xml trouble
Saransoft84 Oct 14, 2009 7:06 AM (in response to Kristtee)Hi,
Just change the array value from both image and text when u click on the datagrid.
If u click the first data in the datagrid mean u pass the array value to 0.
myTxt.text = desc[0]
// Set myTxt as target for scroll bar.
mySb.scrollTarget = myTxt;
var aLoader:UILoader = new UILoader();
aLoader.scaleContent = false;
aLoader.x = 10;
aLoader.y = 10;
aLoader.width = 320;
aLoader.height = 150;
aLoader.source = img_name[0]
if u click the second one the pass the value to 1
myTxt.text = desc[1]
// Set myTxt as target for scroll bar.
mySb.scrollTarget = myTxt;
var aLoader:UILoader = new UILoader();
aLoader.scaleContent = false;
aLoader.x = 10;
aLoader.y = 10;
aLoader.width = 320;
aLoader.height = 150;
aLoader.source = img_name[1]
Like wise the others
Saransoft
-
8. Re: as3 xml trouble
Kristtee Oct 15, 2009 2:07 AM (in response to Saransoft84)sorry it does not do anything. just the same.

