Xmllist Array
OK I can make a XMLList from the "title" attributes (there are 5) in my xml. Now I'm trying to get them in to an array (named titleArray) that I will use to populate 5 text boxes. So I am trying to loop through the list to populate the array. This is where I'm at.
Code: var titleArray:Array = new Array();
function parseSSP(sspstuff:XML):void {
trace("XML Output"); trace("------------------------");
var sspAttributes:XMLList = sspstuff.album.img.attribute("title");
for (var i:int=0; i<sspAttributes.length(); i++) { titleArray.push(sspAttributes[i]); trace(titleArray); //} } } this is what it returns
Code: XML Output ------------------------ Image TItle 1 Image TItle 1,Image TItle 2 Image TItle 1,Image TItle 2,Image TItle 3 Image TItle 1,Image TItle 2,Image TItle 3,Image Title 4 Image TItle 1,Image TItle 2,Image TItle 3,Image Title 4,Image Title 5 I just want an array that contains the 5 title tames so I can reference like so.
Code: trace(titleArray[2]) and return "Image TItle 3" etc.
Thanks for any help!
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 01-08-2009, 06:14 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Xmllist Instead Of Array Collection
how can i make this fuction work using an XMLList instead of an array collection?
ActionScript Code:
private function findIndexByValue(collection:ArrayCollection, key:String, value:String):Number
{
var index:Number = 0;
for (var i:int = 0; i < collection.length; i++)
{
if(collection[i][key] == value)
{
index = i;
}
}
return index;
}
XML: Convert XMLList To Array Or Comma Delimited List
Consider this XML:
var xml:XML =
<xml>
<thing id="1">one</thing>
<thing id="2">two</thing>
<thing id="3">three</thing>
<thing id="4">four</thing>
<thing id="5">five</thing>
<thing id="6">six</thing>
<thing id="7">seven</thing>
</xml>
I want to turn it into this:
"one,two,three,four,five,six,seven"
Or this:
["one","two","three","four","five","six","seven"]
What's the simplest way? Ideally I'd like to do it in one line, if it's not too obtuse.
XMLLIST To New XML?
Ok I have spent 10 hours on this and I am going nuts.
I have this XMLLIST:
<group type="BagCategory" id="1"/>
<group type="BagCategory" id="2"/>
<group type="BagCategory" id="3">
<component ticket="0" type="NetworkPrinter" id="9"/>
<component ticket="0" type="NetworkPrinter" id="11"/>
<component ticket="0" type="NetworkPrinter" id="2"/>
</group>
<group type="BagCategory" id="4"/>
<group type="BagCategory" id="5"/>
<group type="BagCategory" id="6"/>
<group type="SoftwareCategory" id="12"/>
<group type="DevCategory" id="23"/>
<group type="BapCategory" id="29"/>
<group type="BapCategory" id="30"/>
<group type="BapCategory" id="31"/>
<group type="BapCategory" id="32"/>
I am trying to filter through this XMLLIST and create an new XML or XMLLIST file without the component (sub category) being included.
I have tried xml.name().localName = "group" as well as several other things and it keeps put those in my XML file.
What gives!:
Is There An XmlList
ok new question
load xml ... good
then I want part of the xml so I go
ActionScript Code:
var subXML:XMLList =myXML.images.image.subxml;
and that works great but.... not all images have subxml so how do I test to see if the subxml is there to retrieve (not empty);
mm
Is XML (or XMLList) Appropriate For Internal Use?
I wrote a prototype in procedural AS2 that took items from a mySQL database and displayed them as cards on the user's screen. The cards could be rearranged and edited, and then posted back to the server.
I created an array for each property (e.g. authorArray, contributorArray, etc.) and gave each card a number. So card 5 would display authorArray[5], contributorArray[5], etc.. I pushed the data to/from the server with sephiroth's Serializer class and php serialize();.
I'm building a production version in object-oriented AS3. I'm wondering if it would be appropriate to store each card as an XML object.
Code:
<card id ="5"><author>Mike</author>
<contributor>Harry</contributor>
<contributor>Jonas</contributor></card>
I expect as many as 1000 or more cards in memory at a time, including both images and text. Should I store my data as an XMLList that can be sent/received from PHP? Should I convert them all to Arrays for internal processing, and then back to either XML or serialized strings for exportation? My biggest priority is speed, with a secondary emphasis on ease of coding.
Thanks!
Getting XMLList Order
Okay, I can get this XML to sort and spit out the numbers in the right order, but I can't drill down through the list to find the 1st, 2nd, 3rd, 4th or 5th score attribute in the list and place it in a dynamic textfields called, schoolScore1, 2, 3, 4, 5.
I know the code is [0],[1],[2],[3],[4] but I can't figure out where it goes. This should be simple if I wasn't such a noob.
Code:
var schooldata:XML = <schoollist>
<school label="ISM School" totalscore="567" </school>
<school label="West Jordan" totalscore="425"</school>
<school label="Copper Hills" totalscore="516"</school>
<school label="Brighton High" totalscore="215"</school>
<school label="Hillcrest High" totalscore="512"</school>
</schoollist>;
var schoolList:XMLList = schooldata.school;
var item:XML;
for each(item in schoolList) {
book.schoolScore1.text = (item.attribute('totalscore'));
book.schoolScore2.text = (item.attribute('totalscore'));
book.schoolScore3.text = (item.attribute('totalscore'));
book.schoolScore4.text = (item.attribute('totalscore'));
book.schoolScore5.text = (item.attribute('totalscore'));
XML, XMLList And XMLListCollection.Which One?
What is the differnces of theese 3?Which one to use, when and where?For example i want to create a datagrid that will have for dataprovider the following xml data
Code:
<books>
<book id="the great escape">
<chapter book="the great escape">
<title>Ascent</title>
</chapter>
<chapter book="the great escape">
<title>Descent</title>
</chapter>
<book>
<book id="the forgotten">
<chapter book="the forgotten">
<title>Lost</title>
</chapter>
<chapter book="the forgotten">
<title>Found</title>
</chapter>
<book>
</books>
I am supposed to pass the chapters in the xml and then it will automatically pass the chapter in the book it belongs based on the book atribute of the chapter.If i use xmllist i can say
Code:
if(xmllist.book.(@id==chapter.@book){
//how can i add the chapter and not update the whole xmllist
}
On the other hand, if i use xmllistcollection i can't use the filter in the if clause but i can use the xmllistcollection.addItem to just add one item and not to update the whole xmllistcollection
XMLList And Xml Tag References
Here's what works:
ActionScript Code:
xml = new XML(e.target.data);
trace(xml); // outputs: <images>
// <image>01.jpg</image>
// <image>02.jpg</image>
// </images>
Here's where it doesn't:
ActionScript Code:
xml = new XML(e.target.data);
trace(xml); // outputs same as above
var il:XMLList = xml.images;
trace(il); // doesn't output anything
I thought it might be an error with my xml file, but it seems to load fine and it also tried this and it worked fine:
ActionScript Code:
xml = new XML(e.target.data);
trace(xml); // outputs same as above
var il:XMLList = xml.children();
trace(il); // outputs: <image>01.jpg</image>
// <image>02.jpg</image>
Does anyone know what I am doing wrong in that second snippet of code? Could it still be a problem with the xml file?
XMLList XML Problem
Hi, this one is driving me through the roof. i have some xml....
Code:
<sections>
<section name="about">
<component name="textcontent" x="30" y="200"/>
</section>
<section name="portfolio">
<component name="mediaview" x="30" y="200"/>
<component name="textcontent" x="30" y="200"/>
</section>
</sections>
and this code...
ActionScript Code:
var curXML = xml.sections.section.(@name == currentSection/*either "about" or "portfolio"*/).component;
if (curXML.length() == 1) {
curXML = new XML(curXML);
trace(curXML); // traces blank space
}
if (curXML.length() == 2) {
curXML = new XMLList(curXML);
trace(curXML); // traces <component name="mediaview" x="30" y="200"/><component name="textcontent" x="30" y="200"/>
}
what im trying to do is parse the xml and generate "components" based on the passed xml. but, as you see it only works with multiple children under a section and not just a single one. ive tried my different methods, trying to trick it in to thinking thats its just one single xml node but, to no avail. and there doesnt seem to be that much on the topic. so if you can please, please help and point me to what im doing wrong. thanks.
XMLList Question
hi,
im completely stuck with the following problem:
i'm tryin' to create a Menu from XML.
ActionScript Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="SiteForge" creationComplete="onCreationComplete();">
<mx:Style source="AppStyles.css" />
<mx:Script>
<![CDATA[
[Bindable]
//Window (MXML Component)
public var prefWindow:PreferencesWindow;
[Bindable]
//Window (MXML Component)
public var utilWindow:UtilWindow;
private function onCreationComplete():void
{
prefWindow = new PreferencesWindow();
prefWindow.open();
utilWindow = new UtilWindow();
utilWindow.open();
var main:Main = Main.getInstance();
main.initialize(this, menuData, prefWindow, utilWindow);
]]>
</mx:Script>
<mx:XML id="menuData" format="e4x">
<root>
<AppMenu label="{String(this).substr(0, String(this).length-1)}">
<Preferences label="Preferences..." cmd="core.window.commands.WindowShowCommand" rcv="{prefWindow}" />
<Separator />
<Quit label="Quit" cmd="core.nativeapplication.ApplicationExitCommand" rcv="{this}" />
</AppMenu>
<WindowsMenu label="Window">
<Utility label="Utility" cmd="core.window.commands.WindowShowCommand" rcv="{utilWindow}" />
</WindowsMenu>
</root>
</mx:XML>
</mx:WindowedApplication>
The Main Class:
ActionScript Code:
package
{
import core.Command;
import core.DeclarativeMenu;
import flash.desktop.NativeApplication;
import flash.display.NativeMenu;
import flash.display.NativeWindow;
import flash.events.Event;
import flash.utils.getDefinitionByName;
import mx.core.Window;
PreferencesWindow;
import mx.core.WindowedApplication;
WindowedApplication;
Command;
import core.window.commands.WindowShowCommand;
WindowShowCommand;
import core.window.commands.WindowHideCommand;
WindowHideCommand;
import core.nativeapplication.ApplicationExitCommand;
ApplicationExitCommand;
public class Main
{
static private var instance:Main;
private var application:WindowedApplication;
private var applicationMenu:NativeMenu;
private var windowMenu:NativeMenu;
private var preferencesWindow:Window;
private var utilityWindow:Window;
public function Main(singletonEnforcer:SingletonEnforcer) {}
public static function getInstance():Main
{
if (Main.instance == null)
{
Main.instance = new Main(new SingletonEnforcer());
}
return Main.instance;
}
public function initialize(app:WindowedApplication, model:XML, prefWindow:Window, utilWindow:Window):void
{
application = app;
preferencesWindow = prefWindow;
utilityWindow = utilWindow;
//loadMenuDefinition();
buildMenu(model);
}
public function doCommand(event:Event):void
{
if (event.target.data != null)
{
//cast XMLList to String
var className:String = event.target.data.command.toString();
//convert className to Class object
var commandDef:Class = getDefinitionByName(className) as Class;
/*
here ist my problem:
i want the Window instance and WindowedApplication instance (event.target.data.receiver)
to be as their type and attach them as argument to the generated command classes.
I know all contained nodes are type XMLList and the attributes are Strings
I tried:
var s:String = event.target.data.receiver.toString();
var r:* = s as Object //must be Object because of flexibility
no success (type coercion failed...)
var s:String = event.target.data.receiver.toString();
var r:* = getDefinitionByName(s) as Object;
not working either
Is there any workaround around?
*/
/* var receiverName:String = event.target.data.receiver.toString();
var receiverDef:Class = getDefinitionByName(receiverName) as Class;
trace(receiverDef); */
/* var currentCommand:Command = new commandDef(test);
currentCommand.execute(); */
}
event.preventDefault();
}
private function buildMenu(data:XML):void
{
//var menuTree:XML = new XML(data);
//MAC
if (NativeApplication.supportsMenu)
{
NativeApplication.nativeApplication.menu = new DeclarativeMenu(Main.instance, data);
}
//WIN
if (NativeWindow.supportsMenu)
{
application.stage.nativeWindow.menu = new DeclarativeMenu(Main.instance, data);
}
}
}
}
class SingletonEnforcer {}
The DeclarativeMenu Class:
ActionScript Code:
package core
{
import flash.display.NativeMenu;
import flash.display.NativeMenuItem;
import flash.events.Event;
import mx.messaging.management.ObjectInstance;
public class DeclarativeMenu extends NativeMenu
{
private var _client:Object;
public function DeclarativeMenu(client:Object, XMLMenuDefinition:XML)
{
super();
_client = client;
createMenu(this, XMLMenuDefinition.children());
}
private function createMenu(menu:NativeMenu, menuNodes:XMLList):NativeMenuItem
{
var menuItem:NativeMenuItem;
var submenu:NativeMenu;
for each (var child:XML in menuNodes)
{
if(String(child.@label).length > 0)
{
menuItem = new NativeMenuItem(child.@label);
menuItem.name = child.name();
menuItem.data = (child.@cmd != null && child.@rcv != null) ? {command:child.@cmd, receiver:child.@rcv} : null;
menuItem.addEventListener(Event.SELECT, _client.doCommand);
} else {
//menuitem = separator
menuItem = new NativeMenuItem(child.name(), true);
menuItem.name = child.name();
}
menu.addItem(menuItem);
if(child.children().length() > 0)
{
menuItem.submenu = new NativeMenu();
createMenu(menuItem.submenu, child.children());
}
}
return menuItem;
}
}
}
Please help!
Thanks.
XMLList Access
What I want to do is very simple. I have an XMLList. NOT an XML, but an XMLList. I know the name of the element I want in the XMLList. In other words, I know the element's
<name></name>
Now, what I want to do is:
return an XML for the element with that name
Maybe there are more than one element with that name. What would be just as good is if I could:
return an XMLList for all the elements with that name
Either would be fine. There must be a glaringly simple answer sitting directly in my blind spot, right?
XmlList And CDATA
Hey Everyone,
I'm running into an issue that I've just noticed in a 95% complete project. The xml I'm pulling from has a person which contains 3 attributes, an image, a description and a name. After loading in the descriptions I noticed that I was losing my punctuation, commas, apostrophe, etc. I did some googling and found it was the xml parser, so I tried the escape char ' but no luck. I did some further digging and found that it would be better to wrap the description in a CDATA tag. This bring me to my question, how to I access the content inside the cdata tag from an xmllist? Since this project is nearly complete it would be a massive headache to go back and remove the xmllist from the code. This is my first xml heavy project so please forgive any newbness.
Thanks in advance.
Convert XMLList To XML In AS3?
Hello,
I am trying to figure out how to convert an XMLList that I retreived from an XML instance back into well-formed XML in Flash CS3. Here is what I am doing.
- I have an XML document loaded and I am displaying the contents in a datagrid component (which is working well).
- I am then filtering the XML to obtain a subset of data by first obtaining an XMLList representing all elements of my XML instance and then filtering the list on a particular element (this is working well).
- Now I want to display my filtered results in the datagrid and here lies the problem because the datagrid can't use an XMLList as a dataprovider. How do I convert this XMLList back into well formed XML so I can use it as my grid's dataprovider? I need to somehow get a root tag back on.
Could I somehow use toXMLString() and then convert that to XML?
Thank you in advance for any advice.
TH
Push For XMLList
I've got a fairly complicated criteria to select elements from some XML. So I thought I'd just make one XMLList, and then for each node in that list, push the node into a second XMLList if it meets the criteria I'm looking for.
But I can't find an equivalent for .push() for an XMLList. In fact, XMLList appears to be missing a lot of list manipulation methods that you'd think would be useful for a list: shift() pop() sort() splice() join()
What's up with that? Is there something about XMLList that would make it defy list-based manipulation?
Accessible XMLList
I'm wondering what the most efficient way of making an XMLList available to anything that needs it. Basically, I load images into two movie clips, fade out the one on top, move down one depth, load a new image and the process repeats...the problem is that I'm only able to do the first two images as I'm not sure of how to access the XMLList to change the image.
Once I get that I believe I'll be able to get the rest. Do I have to create a getter function? If so, how would I do that? Here's what I have for the xml loading so far.
Code:
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("../banner_images.xml"));
//LoadXML function
function LoadXML(evt:Event):void{
var xmlData:XML = new XML(evt.target.data);
ParseImgs(xmlData);
}
function ParseImgs(imgInput:XML):void{
var imgAtts:XMLList = imgInput.img.attribute("src");
//trace is fine unless I'm trying to access this information
//outside this function.
trace(imgAtts[0]);
}
Getting Warning Using XMLList.contains()
Hello good people!
I'm having a problem using the XMLList.contains() method. It seems to run like it should, but I keep getting these annoying warnings in the output window:
Warning: 3594: contains is not a recognized method of the dynamic class XMLList.
I'm adding an item from xmllist1 to xmllist2 if its value is as required and if it isn't already present in xmllist2. Here's the code:
Code:
xmllist2 += xmllist1.((value >= required) && (xmllist2.contains(@ID) == false)).@ID;
Does anyone have experience with this warning, or hints on how to get rid of it?
Appreciate it!
XMLList Problem
hi,
I'm about to go insane because of this error:
#1089: Assignment to lists with more than one item is not supported.
I'm working on a project where user can move objects on the screen & press to a button to save their coordinates and press to another button to do next frame etc.. and at the end with a third button it wraps up every frame into one xml...
I'm trying to create something like this :
<frame id="0">
<obj id="1" posx="100" posy="200"/>
<obj id="2" posx="300" posy="100"/>
</frame>
<frame id="1">
<obj id="1" posx="130" posy="20"/>
<obj id="2" posx="300" posy="10"/>
</frame>
etc etc..
so to create this i'm doing something like this one
Code:
public function writeFrames() {
frameTag.@id = frameCounter;
framer += frameTag;
for (var i=0; i<currentFrameArray.length; i++) {
framer.frameTag += <word name= {currentFrameArray[i].nameTag} posX={currentFrameArray[i].x} posY={currentFrameArray[i].y} /> }
}
when I run this it works for the first frame and traces this:
<frame id="0">
<word name="9" posX="-25" posY="-25"/>
<word name="8" posX="-52" posY="27"/>
</frame>
but when I try to do the same thing to write second frame data I get this:
TypeError: Error #1089: Assignment to lists with more than one item is not supported.
I'm not a as3 master or something but I've been finding my way around quite fine until this thing.
I was thinking creation of the XML was the easiest part but I was damn wrong...
any help will be greatly appericiated...
Thanks
Splice XMLList Help
How do I splice into an XMLList? I want to add an subtract using splice but I keep getting and error.
How do you do this?
Code:
package {
import flash.display.*;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.*;
public class xmlimport extends MovieClip {
private var xmldata:XML;
private var addSlideBtn:newSlideBtn=new newSlideBtn;
private var nxtBtn:nextSlideBtn=new nextSlideBtn;
private var allSlides:Object=new Object;
public var tit:XMLList=new XMLList;
private var num:Number=0;
private var _currentSlide:Number=0;
private var titleTxtBx:TextField=new TextField;
public function xmlimport() {
xmldata=new XML ;
var xmlURL:URLRequest=new URLRequest("xml.xml");
var xmlLoader:URLLoader=new URLLoader(xmlURL);
xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);
}
//get xml data in object
public function xmlLoaded(event:Event) {
xmldata=XML(event.target.data);
var all:XMLList=xmldata.modules.module;
allSlides=all;
tit=all.title;
////add text boxes
titleTxtBx.autoSize="left";
titleTxtBx.y=200;
addChild(titleTxtBx);
titleTxtBx.text=tit[0];
/////////////////////////
addChild(addSlideBtn);
addChild(nxtBtn);
nxtBtn.y=50;
addSlideBtn.addEventListener(MouseEvent.MOUSE_DOWN,insertButton_MOUSEDOWN);
nxtBtn.addEventListener(MouseEvent.MOUSE_DOWN,nxtBtn_MOUSEDOWN);
//
populateScreen(0);
}
public function saveScreen() {
tit[num]=titleTxtBx.text;
}
public function populateScreen(s) {
titleTxtBx.text=tit[num];
}
//if we come to the last slide we start over at 1
public function gotoFrame(s) {
num=s;
if (num >= allSlides.length()) {
num=0;
} else if (num < 0) {
num=allSlides.length();
}
populateScreen(num);
}
public function insertButton_MOUSEDOWN(e:MouseEvent):void {
allSlides.splice(num,0);
trace(allSlides);
}
public function nxtBtn_MOUSEDOWN(e:MouseEvent):void {
gotoFrame(num + 1);
}
}
}
Code:
<?xml version="1.0" encoding="utf-8"?>
<presentation courseName ="" lesson="" >
<modules>
<module>
<title>first</title>
<slide/>
<bullets>this is the first one</bullets>
<bodyText/>
<checkpoint/>
<question/>
<answers/>
<correctAnswer/>
<avatarAnswer/>
</module>
</modules>
</presentation>
Sorting A XMLlist
Hi,
out of a xml i build a sub navigation. all my data are stored in a XMLlist. is it somehow possible to sort the XMLlist accoring an attribute?
I know that it's possible to sort an array but i would like to keep all data in the XMLlist.
this is my xml:
Code:
<submenu name="Work" >
<name type="new" >
Class to build the sub navigation:
Code:
_ctnSubNL = new subNaviList(_xmlL, _subY);
addChild(_ctnSubNL);
the parameter _xmlL is a XMLlist. I would like to send only the data where the type attribute is "new". Is this possible somehow?
Thanks a lot
-tukinu
XMLList HtmlText ?
hi there,
I'm loading a xml file into my flash and defining it as XMLList! everything works perfect! only thing: previously I my code looked like this.
mytextfield.text = myxmlobject
but now I added a simple link in my xml file (only on line)
<a href = "mailto:hello@hello.com">hello@hello.com</a>
of course if I'm now previewing my flash I can't see this line, but even if I change the text attribut into htmlText nothing's there! why??
mytextfield.htmlText = myxmlobject
Is the htmlText attribut not working with a XMLList?
Adding Node To XMLList
I have the following 'myXML' XML object:
Code:
<layout>
<region id="main" left="295" width="458" top="35" height="343"/>
<region id="subs" left="265" width="520" top="440" height="50" />
<region id="links" left="45" width="150" top="70" height="180" />
<region id="video" left="48" width="160" top="330" height="125" />
<region id="links-down" left="45" width="150" top="165" height="95"/>
<region id="links-small" left="45" width="150" top="60" height="100"/>
</layout>
and '<region>' nodes loaded inside a XMLList object called 'xml_list':
Code:
var xml_list:XMLList = new XMLList(myXML.region);
and i would like to add for example this node to that XMLList:
Code:
<region id="test" left="0" width="0" top="0" height="0"/>
How can i accomplish that?
thanks in advance,
best regards
XMLList Element Count
I'm using a 'for each...in' loop to get the values from certain elements in my xml document.
That's working no problem.
Just wondering... is there a simpler/smarter/faster way to determine the total number of particular elements or nodes in the xml?
For example, my xml document right now has an element called <thumb> in every item.
Is there a quick way for ActionScript to determine how many <thumb> elements there are in total?
At the moment, my for each...in loop creates an array and then I can get the array's length. Is there a smarter way to do this?
Adding To Elements XMLList
hello all,
I need help adding elements to an XMLList.
so I have two XMLLists: oldList, and newList.
I perform a sorting operation with the use of arrays.
after the sorting operation, i need to start populating the newList
with values from the oldList. The order of elements would be determined
by the values retrieved from the array.
Code:
for(var i:Number=0; i<array.length; i++){
var getInd:Number = array[i].ind;
newList = oldList[getInd];
}
any ideas how the code above could be worked out?
cheers
Adding Node To XMLList
I have the following 'myXML' XML object:
Code:
<layout>
<region id="main" left="295" width="458" top="35" height="343"/>
<region id="subs" left="265" width="520" top="440" height="50" />
<region id="links" left="45" width="150" top="70" height="180" />
<region id="video" left="48" width="160" top="330" height="125" />
<region id="links-down" left="45" width="150" top="165" height="95"/>
<region id="links-small" left="45" width="150" top="60" height="100"/>
</layout>
and '<region>' nodes loaded inside a XMLList object called 'xml_list':
Code:
var xml_list:XMLList = new XMLList(myXML.region);
and i would like to add for example this node to that XMLList:
Code:
<region id="test" left="0" width="0" top="0" height="0"/>
How can i accomplish that?
thanks in advance,
best regards
Deleting The Contents Of An XMLList
hey. so i have an XMLList, and i want to delete its contents. how can i do this?
ActionScript Code:
subXMLList = _data.section.(@name == mainS).children()[2].page.(@name == subS);
that holds the right value, but how can i keep the variable, but remove its value? these don't work:
ActionScript Code:
subXMLList = null;
subXMLList = '';
delete subXMLList;
Help With A Button That Pulls From A XmlLIST
hey, i need some help
I have a drop down menu with 5 options. The drop down menu is a comboBox that is xml driven and each of the 5 options links to a different video. Now I added 5 buttons and each button i want to pull up the same video as the corresponding option in comboBox. However I cant get find any code that will say "just get video 1 from the xmlList" or "just get video 1 from the xmlList" iv been looking for abut 2 hours, can some one help me?
Issues With A For Each Loop On XMLList
not sure if i'm just being stupid with this, but it's really starting to annoy me, so any help would be appreciated.
this is my xml,
<group id="locations">
<item value="birmingham"/>
<item value="london"/>
<item value="brighton"/>
<item value="manchester"/>
<item value="leeds"/>
<item value="glasgow"/>
</group>
the xml is then passed to a function which runs this code.
var list : XMLList = node.descendants( "item" );
var element : XML;
for each( element in list )
{
trace("element:" + element );
trace("element:" + element.name() );
}
for some reason though, the first trace just returns 'element:' but the second trace returns 'item'? Also if i try this,
trace( element is XML );
it returns true?
I've also found that if i add another xml node inside <item> it works properly and traces out the whole <item> node?
Any one got any ideas?
Trying To Fill A Textbox With XMLList
I've attached the code below. It is only displaying the last entry. How can I get it to display all of them?
Attach Code
var list:XMLList = xml.na.officelist.office;
for( var i:uint = 0; i < list.length(); i++){
na2_txt.text = list[i];
}
Edited: 11/26/2008 at 06:14:43 AM by sehart
[Q] Difference Between XML, XMLList And XMLDocument?
Hi all
Could any body explain ..
what is the difference between XML, XMLList, and XMLDocument
Code:
var theList:XML = new XML(theXML.data);
As the above syntax can retrieve the XML data, why we still have to use XMLList ??
Thanks
Cant Convert XMLList To DisplayObject
I have a slideList being populated by XML. Its datascource is just an ID. I added an event listener when you rollOver the listItem. I keep getting this error
Code:
TypeError: Error #1034: Type Coercion failed: cannot convert XMLList@359defb1 to flash.display.DisplayObject.
at Vforum/::showThumb()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::SelectableList/fl.controls:SelectableList::handleCellRendererMouseEvent()
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///E|/New%20Vforum%20AS3/data/slide01.jpg
at Vforum$iinit()
the problem resides in my showThumb function..anyone know whats up?
ActionScript Code:
package { import flash.text.TextField; import flash.display.MovieClip; import flash.net.URLLoader; import flash.net.URLRequest; import flash.errors.*; import flash.events.*; import fl.events.ListEvent; public class Vforum extends MovieClip { private static const MEDIAPATH:String = "data/"; private static const PADNUM:String = "01_"; private static const SLIDESCALE:Number = 0.7; private var xmlData:XML; private var xmlLoader:URLLoader = new URLLoader(); private var thumbLoader:URLLoader = new URLLoader(); private var xmlList:XMLList; public function Vforum():void { var xmlSource:String = xmlSheet.text; xmlLoader.addEventListener(Event.COMPLETE, onComplete); xmlLoader.load(new URLRequest(MEDIAPATH + xmlSource)); slideList.addEventListener(ListEvent.ITEM_ROLL_OVER, showThumb); //slideList.addEventListener(ListEvent.ITEM_CLICK, showData); //slideList.addEventListener(ListEvent.ITEM_ROLL_OUT, showOrigThumb); } private function onComplete(e:Event):void { xmlData = new XML(xmlLoader.data); xmlList = new XMLList(xmlData..Slide); for (var i:uint = 0; i < xmlList.length(); i++) { var title = xmlList[i].Title; var slideID = xmlList[i].@id; var bgSwf = xmlList[i].BGSwf; var swfFile = xmlList[i].SwfFile; var slideText = xmlList[i].SlideText; slideList.addItem({label:slideID + ". " + title, data:slideID}); } } private function showThumb(e:ListEvent):void { var thumb = e.item.data; if (thumb >= 10) { thumbLoader.load(new URLRequest(MEDIAPATH + "slide" + thumb + ".jpg")); } else { thumbLoader.load(new URLRequest(MEDIAPATH + "slide0" + thumb + ".jpg")); } thumbs.addChild(thumb); } }}
XMLList Accessible In All Classes
Hey, me again.
I have a XMLLoader class and after I've got the XML I would like to have the XMLLIst accessible in all my classes.
Until now I pass the XMLList as a parameter to other classes but does anyone maybe a better way?
cheers
Blank Nodes In XMLList
Hi
I have tracks with information set like this in an XML:
Code:
<track>
<artist>The Artist</artist>
<title>The Title</title>
<label>The Label</label>
</track>
I have about 20 of those in an XML file. If I leave a one of those children blank, like this:
Code:
<title></title>
It adds nothing to the XMLList for that spot and what happens is everything is offset by one space. If I do it like this:
Code:
<title> </title>
It works that way and everything lines up properly. Am I approaching this the wrong way? How can I get it to add a blank spot in the XMLList so when I cycle through it with a for loop it doesn't offset the whole thing. In the examle below, tracks is an array.
Code:
xml = new XML(e.target.data);
var il:XMLList = xml.track;
for(var i:uint=0; i<il.length(); i++)
{
var track:Object = new Object;
track.artist = il.artist.text()[i];
track.title = il.title.text()[i];
track.label = il.label.text()[i];
tracks.push(track);
}
Adding Node To XMLList Won't Work
I'm trying to use this code to add data to an XMLList but it's not quite working:
Code:
var artist:String = event.currentTarget.uid;
var song:String = event.currentTarget.name;
var videoPath:String = event.currentTarget.id;
personalPlaylist += <track xmlns="http://xspf.org/ns/0/">
<identifier>artist</identifier>
<title>song</title>
<location>videoPath</location>
</track>;
but that returns
Code:
<track xmlns="http://xspf.org/ns/0/">
<identifier>artist</identifier>
<title>song</title>
<location>videoPath</location>
</track>
in the XMLList. These are all on a clickHandler event. How do i pass these variables into the XMLList?
Return XMLList To Document Class
Hello
I am making the jump from AS2 to AS3 and trying to load an xml file the return an XMLList to the document class, for use later in the code. I don't know at which point to return the XMLList, or the necessary events that would facilitate that. Any help would be greatly appreciated.
These lines are in the document class
ActionScript Code:
import flash.display.Sprite;
import flash.events.Event;
import com.snacktreat.lieberman.xmlTools.*;
public class lieberman_document_class extends Sprite{
var xmlSetup:config = new com.snacktreat.lieberman.xmlTools.config();
var textContent:XMLList;
public function lieberman_document_class(){
init();
}
private function init():void{
textContent=xmlSetup;
}
}
and here is the config class
ActionScript Code:
import flash.display.Sprite;
import flash.net.*;
import flash.events.Event;
public class config extends Sprite
{
public function config():void
{
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);
var xml:XML;
function onLoaded(e:Event):void
{
xml = new XML(e.target.data);
var il:XMLList = xml.item;
}
loader.load(new URLRequest("http://www.snacktreat.com/lieberman/config/config.xml"));
}
}
I am trying to figure out how to return il to the document class. Thanks.
Type Coersion Failure: XMLList And XML
Hey everyone
When i cast this xml to a method:
Code:
<videosection>
<videourl>videos/intro.flv</videourl>
</videosection>
... I get this:
Code:
TypeError: Error #1034: Type Coercion failed: cannot convert XMLList@2fbd8311 to XML.
at MainClass/init()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at XMLLoader/saveXML()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Howcome I get this error, when it's not an XMLList? There's only 1 root node?
The method takes an XML object as parameter.
XmlList Attributes Index Order
My xml file that is dynamically generated and contains an attribute that may or may not exist in every node. In this case it's "title"
<album>
<img file="001" title="title1"/>
<img file="002" title="title2"/>
<img file="003"/>
<img file="004" title="sometext"/>
</album>
img file = an image that get's displayed, and I want to test when each file is displayed what the "title" attribute =. That all works great. So depending on what img file I'm using (based on index position), I'm grabbing the title attribute with the position index. The problem is when an attribute is missing the next "title" attribute is moving down into that index position.
so when I look for the attribute like this.
ActionScript Code:
var myList:XMLList = xmlstuff.album.img;
trace(myList.@title[2]) //output = "sometext" but I want undefined, it moved down the index.
trace(myList.@title[1]) //output = "title 2" what I expect, no missing attributes before it, in the proper position.
Is there a way for the list to hold it's index position based on the img tag and then let me dig down via dot and attribute name? I've tried all sorts of combos with no success.
thanks for any help!
Filtering XMLList By Partial String
Hi all,
I have an XMLList from a feed that takes the form shown below and has about 90 'contact' nodes within it.
I can use E4X to filter the list by a node value and display all contacts from the uk say but now I am trying to search by name as the user types in to a text field and am stuck.
What I want is that each time a character is entered in the search field a list is created that contains only objects whos firstName node value contains what the user has entered. This might be a full name or just the first few letters.
I managed to do this easily with an array of data by using Array.filter() and String.search() but with an XMLList I am stuck. I could create an array I suppose but that seems dirty when the list is there to be used.
Any ideas?
Cheers all
Attach Code
<contactSheet>
<contact>
<firstName>John</firstName>
<secondName>Smith</secondName>
<country>UK</country>
<office>Office Name</office>
<extension>001</extension>
<directDial>0000 111 2222</directDial>
</contact>
</contactSheet>
Adding Node To XMLList Object
I have the following 'myXML' XML object:
Code:
<layout>
<region id="main" left="295" width="458" top="35" height="343"/>
<region id="subs" left="265" width="520" top="440" height="50" />
<region id="links" left="45" width="150" top="70" height="180" />
<region id="video" left="48" width="160" top="330" height="125" />
<region id="links-down" left="45" width="150" top="165" height="95"/>
<region id="links-small" left="45" width="150" top="60" height="100"/>
</layout>
and '<region>' nodes loaded inside a XMLList object called 'xml_list':
Code:
var xml_list:XMLList = new XMLList(myXML.region);
and i would like to add for example this node to that XMLList:
Code:
<region id="test" left="0" width="0" top="0" height="0"/>
How can i accomplish that?
thanks in advance,
best regards
Multiple XML Files To Single XMLList
I am trying to load 4 XML files into flash and read all of the data as if it were a single XML file. The 4 XML files are all formatted exactly the same. Here is an example.
<calendar>
<event>
<program_name>Nutcracker in a Nutshell</program_name>
<schedule_date>November 21, 2007</schedule_date>
<schedule_time>10:00 AM</schedule_time>
<schedule_status>Open</schedule_status>
<program_description>Bring the family for a "Behind the Scenes" tour of the Kansas City Ballet's "The Nutcracker" without ever leaving the library. See professional costumes, props and special effects. Learn how the sets and costumes are made. Open the door to the magic of the ballet.</program_description>
<age_range>Ages 3 and up</age_range>
<branch_name>Boardwalk</branch_name>
</event>
<event>
<program_name>Night Before Christmas Carol</program_name>
<schedule_date>December 3, 2007</schedule_date>
<schedule_time>10:00 AM</schedule_time>
<schedule_status>Open</schedule_status>
<program_description>Join Charles ****ens in his study for a very special night. On this evening in 1843, he creates his holiday classic, "A Christmas Carol". Renowned ****ens scholar, author, playwright and lecturer, Elliot Engel has crafted a work that allows David zum Brunnen to portray the 17 Christmas Carol characters and Charles ****ens himself. Recommended highly by the ****ens family, MCPL is privileged to offer this performance to continue its ****ens' tradition!</program_description>
<age_range>Ages 8 and up</age_range>
<branch_name>Boardwalk</branch_name>
</event>
<event>
<program_name>Holiday Concert Featuring Kacico Dance and Fontana Trio</program_name>
<schedule_date>December 8, 2007</schedule_date>
<schedule_time>10:30 AM</schedule_time>
<schedule_status>Open</schedule_status>
<program_description>Presented by Kacico Dance, a professional dance company serving the KC metro area and the mid-west region. The lovely, classical sounds of a live string trio combined with exquisite contemporary dance make this hour long performance a unique holiday treat. The performance is comprised of classical, secular, and holiday music. The dancing is superbly entertaining.</program_description>
<age_range>All ages</age_range>
<branch_name>Boardwalk</branch_name>
</event>
<event>
<program_name>Mr. Christmas</program_name>
<schedule_date>December 15, 2007</schedule_date>
<schedule_time>2:00 PM</schedule_time>
<schedule_status>Open</schedule_status>
<program_description>Jim Cosgrove presents "Mr. Christmas"! Celebrate the holidays with singing, dancing! Fun for the whole family.</program_description>
<age_range>All ages</age_range>
<branch_name>Boardwalk</branch_name>
</event>
</calendar>
What I need to do is import all 4 files and then essentially merge all of the data based upon the schedule_date childNode, so that all events are listed chronologically. What I currently have is a scrolling events calendar that populates and displays the event data on a row, then populates another row and moves the rows up. Once 5 rows are displayed, I call a removeChildAt(1). Run through all of the nodes and start again, looping infinitely. Any suggestions on the best way to approach this particular issue? Thanks
XMLList Object In For Statement References NULL
I am a new flash developer and I cannot seem to understand this problem. Whenever I try and trace one of these variables of type XMLList they all return NULL except for the last one in the array.
The createDatsSets() function is designed to pull XMl data and copy it to an variable of type XMLList which resides in an array. This should happen 8 times to add data to all 8 variables. It works fine with a single variable but, in the for statement when I try and trace any of the variables in the xmlList array only the last one has XML data in it.
I think maybe (event.COMPLETE, ) is causing this.
The trace statements output like this:
1
2
2
2
2
2
2
2
2
NULL
3
3
3
3
3
3
3
3
I don't understand how the trace(xmlList[4]); statement executes before the trace("3") statement. It's confusing me!!
Attach Code
package card{
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class CreateCard extends MovieClip{
public function CreateCard(){
loadCard();
}
/*This is the card function for creating a new card object and injecting card
data from various xml attributes.*/
private function loadCard():void{
var xmlList_DMF:XMLList;
var xmlList_FoO:XMLList;
var xmlList_HFI:XMLList;
var xmlList_MCt:XMLList;
var xmlList_MoL:XMLList;
var xmlList_SoB:XMLList;
var xmlList_TBT:XMLList;
var xmlList_TDP:XMLList;
var xmlList:Array = [xmlList_DMF, xmlList_FoO, xmlList_HFI, xmlList_MCt, xmlList_MoL, xmlList_SoB, xmlList_TBT, xmlList_TDP];
var setList:Array = ["xml/DMF.xml", "xml/FoO.xml", "xml/HFI.xml", "xml/MCt.xml", "xml/MoL.xml", "xml/SoB.xml", "xml/TBT.xml", "xml/TDP.xml"];
var cardTitle:String = new String();
var idNum:Number = new Number();
var deckList:DeckList = new DeckList();
var iD:String = new String();
iD = deckList.hordeDeckPrimer[1][0];
createDataSets();
function createDataSets():void{
var xml:XML;
var xmlLoader:URLLoader = new URLLoader();
trace("1");
for (var i:Number = 0; i < 8; i++) {
xmlLoader.load(new URLRequest(setList[i]));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
trace("2");
function xmlLoaded(event:Event):void {
xml = XML(event.target.data);
xmlList[i] = xml.children();
trace("3");
}
}
}
trace(xmlList[4]);
}
}
}
package card{
/* This is the initial array containing all of the card ID's and counts of the cards in
a player's deck.*/
internal class DeckList {
var card1:Array = ["SoB_029", 1];
var card2:Array = ["MoL_177", 4];
var card3:Array = ["HFI_162", 4];
var card4:Array = ["TDP_242", 1];
var card5:Array = ["SoB_178", 4];
var card6:Array = ["DMF_002", 3];
var card7:Array = ["TBT_031", 2];
var card8:Array = ["TDP_226", 2];
var card9:Array = ["MoL_091", 3];
var card10:Array = ["SoB_103", 4];
var card11:Array = ["HFI_089", 4];
var card12:Array = ["FoO_076", 3];
var card13:Array = ["HFI_085", 2];
var card14:Array = ["MCt_025", 3];
var card15:Array = ["HFI_232", 4];
var card16:Array = ["MoL_293", 4];
var card17:Array = ["SoB_257", 4];
var card18:Array = ["SoB_250", 4];
var card19:Array = ["MoL_299", 2];
var card20:Array = ["DMF_005", 3];
var hordeDeckPrimer:Array = [card1, card2, card3, card4, card5, card6, card7, card8, card9, card10, card11, card12, card13, card14, card15, card16, card17, card18, card19, card20];
public function DeckList() {
// This is an empty contructor function.
}
}
}
Edited: 11/06/2008 at 11:47:02 AM by maniacalmomba
Adding A Preloader To Images Loaded By XMLList
Hi there,
I think I posted this before in the wrong forums but will post it here since I think this is just a AS3 doubt.
I'm loading several images from XMLList and then placing them into a mc using the For each (img in imglist) loop.
I want to create a preloader for everyone of them from that loop, but calling event listeners to other functions seems not to be working, so I was wondering if you guys new of a system!
thanks!
this is the code:
Code:
imgList = xmldata.images.children();
var initX = shapeX;
var i:int = 0;
for each (var singleImg in imgList) {
var pictLdr:Loader = new Loader();
var getImg:URLRequest = new URLRequest(singleImg);
pictLdr.load(getImg);
var imgBtn:MovieClip = new MovieClip();
imgBtn.addChild(pictLdr);
imagesContainer.addChild(imgBtn);
gallery.push(imgBtn);
imgBtn.y = imagesY;
imgBtn.x = initX + (i * (632 + 22));
i++;
if (imgBtn.x==shapeX) {
imgBtn.alpha = 1;
imgBtn.buttonMode = false;
} else {
imgBtn.alpha = lowAlpha;
imgBtn.buttonMode = true;
}
imgBtn.addEventListener(MouseEvent.ROLL_OVER, imgRollover);
imgBtn.addEventListener(MouseEvent.ROLL_OUT, imgRollout);
imgBtn.addEventListener(MouseEvent.CLICK, moveImages);
}
them images load fine, but I just want to add a preloader for everyone and I have not done this befor in AS3...
any light on this?
Trouble Sorting XMLList - Numerical | Decending
Okay, I can get this XML to sort and spit out the numbers in the right order, but I can't drill down through the list to find the 1st, 2nd, 3rd, 4th or 5th score attribute in the list and place it in a dynamic textfields called, schoolScore1, 2, 3, 4, 5.
I've used the following class, which was the only way I could find to sort an XMLList. Seems dumb to me that AS3 doesn't have a sort function for the XMLList.
http://www.nuff-respec.com/technology/sort-xml-by-attribute-in-actionscript-3
This class did a great job of sorting the total scores in my XML, but I can't drill down and get at each level in the list.
I know the code is [0],[1],[2],[3],[4] but I can't figure out where it goes. This should be simple if I wasn't such a noob.
Code:
var schooldata:XML = <schoollist>
<school label="ISM School" totalscore="567" </school>
<school label="West Jordan" totalscore="425"</school>
<school label="Copper Hills" totalscore="516"</school>
<school label="Brighton High" totalscore="215"</school>
<school label="Hillcrest High" totalscore="512"</school>
</schoollist>;
var schoolList:XMLList = schooldata.school;
var item:XML;
for each(item in schoolList) {
book.schoolScore1.text = (item.attribute('totalscore'));
book.schoolScore2.text = (item.attribute('totalscore'));
book.schoolScore3.text = (item.attribute('totalscore'));
book.schoolScore4.text = (item.attribute('totalscore'));
book.schoolScore5.text = (item.attribute('totalscore'));
I could use all the help I can get. I feel like I've tried just about everything. If there is an easier way of doing this, let me know.
Array, Array HELP - Importing A External File Into N ARRAY - Almost There
I am reading and external file with the following code:
ActionScript Code:
on (release, keyPress "<Enter>") {
lv = new LoadVars();
lv.onLoad = function() {
questions1 = this.filelist0.split(",");
answers1 = this.filelist1.split(",");
for(i=0;i<questions1.length;i++)
//trace(questions1[i]+" "+answers1[i]);
trace(questions1[i]);
//assumes same number of scores in each list
};
lv.load("questions.txt");
}
When I parse the file it puts it into an columar format as it should...however I need it to look like this:
questions1=new Array ("2+4=?","What is the capital of Illinois?","What color is the sky?","10x(5+2)=?");
answers1=new Array ("8","springfield","blue","70");
How do I do that?
Text file look like this:
&questions1=2+4=?,What is the Capital of Illinois?,What color is the sky?,10x(5+2)=?")&
&answers1=8,springfield,blue,70&
Pls Help: Need To Create New Array Taking 3 Random Entries From An Existing Array
Hello
I have a 2d array:
qTeeth[1] = [How many teeth do we have?, 1-10, 11-20, 21-30, 11-20]
etc.
It goes [question, option1, option2, option3, real answer]
I now just want to extract 3 or so of these entries and create a new array with them. Since I want to just use 3 or so questions randomly from a large array of questions.
Does anyone know a good tidy script to do this with??
Thanks in advance,
Ben.
Array Text Into Textfield And Creating New Line For Each Array Element
I have an array called dropTarg1 which stores dropped-in items.
I want to loop through this array and in a textfield, display each array item on a new line of this text field
I think I need to use something like Array.join("/n") but I can't get it working properly. I hope that the /n would create a new line of the text field called reviewBoxContentText.
for(var i:Number = 0; i<dropTarg.length; i++){
with(reviewBoxContent.reviewBoxContentText){
autoSize = true;
text = dropTarg1.join("/n");
}
}
All that is happening though is that the text field displays on a single line with /n in between each array element.
|