Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Checking If A(n XML) Node Has XX Childs



Hi.With an XML file built like:
Code:
<aa> <bb> <cc>something here</<cc> <cc>something here</<cc> </bb> <bb> <cc>something here</<cc> <cc>something here</<cc> <cc>something extra here</<cc> </bb> <bb> <cc>something here</<cc> <cc>something here</<cc> </bb></aa>
I'm calling the two children of the appropriate bb nodes into a text box in my swf. What I'm interested in and couldn't achive yet, is to make flash see if there is the childNode[2] (with nodeValue "something extra" in the above script") within the selected bb and to have it written to a text box in the main scene if it's there.I tried something like
ActionScript Code:
if (node.firstChild.childNodes == 3) {    theTextBox.text = node.firstChild.childNodes[2].nodeValue;}
but it didn't work. Any ideas?



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 12-29-2006, 09:11 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

How Do I Read Different Amount Of Childs In A Node
I parse an xml-file with for example 4 childs with each an attribute.If each xml-file would have 4 childs every time than there is no problem reading the attributes, I can than write 4 lines:

var[0] = xmlfile.firstchild.attribute.ID;
var[1] = xmlfile.firstchild.nextsibling.attribute.ID;
..
var[3] =xmlfile.firstchild.nextsibling.nextsibling.attrib ute.ID;

The problem is that the next time my xmlfile can have 10 or 2 or even 425 childs.
So I need a routine that reads each firstchild's attribute into an array and than the nextsibling and the next sibling and so on... This routine needs to run for "childNode.Length"-times.

OK, but how do I actually read the nextsibling?? How do I change the "pointer" from :

xmlfile.firstchilde.attribute.ID
to
xmlfile.firstchild.nextsibling.attribute.ID;
to
..
xmlfile.firstchild.nextsibling.nextsibling.attribu te.ID

Checking Wheather An Attribute Exist In Node Or Not
Let's say i have the following simple xml structure:


Code:
var xml:XML = new XML (<test id="test">
</test>);
And i would like to test wheather 'id' attibute exists in 'test' node or not. I tried with:


Code:
if (xml.attribute("id") == null){
trace("Attribute doesn't exist...");
}else{
trace ("Attribute exists...");
}
But i get 'Attribute exists' wheather it really exists or not How can i check wheather an attribute exists or not?

thanks in advance,
best regards

Checking Wheather An Attribute Exist In Node Or Not
Let's say i have the following simple xml structure:


Code:
var xml:XML = new XML (<test id="test">
</test>);
And i would like to test wheather 'id' attibute exists in 'test' node or not. I tried with:


Code:
if (xml.attribute("id") == null){
trace("Attribute doesn't exist...");
}else{
trace ("Attribute exists...");
}
But i get 'Attribute exists' wheather it really exists or not How can i check wheather an attribute exists or not?

thanks in advance,
best regards

Using XFTree: Getting The Parent Node Of Selected Node?
I'm using the XFTree component (great component) and I'm hoping there is a way to return the parent node of whatever node is selected in the tree. Does anyone know.

I can use getSelectedNode() to return the selected node for example, but I can't use: getSelectedNode().ParentNode for instance since the selected node that is returned is no longer attached to its original XML object.

Also, (and this is the larger issue) I really have no idea where the documentation is for this. Is there any? Aside from the list o' methods in the actionscript panel I mean.

Thanks in advance!

Finding A Node In XML File Via Node Attrib?
Hi guys,

I thought this was going to be easy! I would like to search an XML file for a particular data set i.e. set of nodes depending on a passed variable. However, storing a subset of my XML file via
ActionScript Code:
var gallery = this.firstChild;
and then searching 'gallery' as you would an array-using a for()-doesn't work since this.firstChild isn't returning an array . Any ideas?
A sample of my XML and function are below.

Cheers!




Code:
<gallery>
<collection title="Christmas 2004">
<picture title="Tiny Disk" thumb="portfolio_images/thumbs/tinydisk.jpg" description="portfolio_text/tinydisk.txt" image="portfolio_images/tinydisk.jpg"/>
<picture title="Plug" thumb="portfolio_images/thumbs/plug.jpg" description="portfolio_text/plug.txt" image="portfolio_images/plug.jpg"/>
</collection>
<collection title="Christmas 2004">
<picture title="Tiny Disk" thumb="portfolio_images/thumbs/tinydisk.jpg" description="portfolio_text/tinydisk.txt" image="portfolio_images/tinydisk.jpg"/>
<picture title="Plug" thumb="portfolio_images/thumbs/plug.jpg" description="portfolio_text/plug.txt" image="portfolio_images/plug.jpg"/>
</collection>
</gallery>
And the AS function....


ActionScript Code:
function getCollection(collection) {    //set the popup invisble when choosing a new gallery    var gallery_xml = new XML();    gallery_xml.ignoreWhite = true;    gallery_xml.onLoad = function(success) {        if (success) {            trace("XML loaded");            var gallery = this.firstChild            trace("gallery:" +gallery instanceof Array);            for(var i=0; i< gallery.length; i++){                trace("searching for collection...");                //find collection data                if(gallery[i].attributes.title==collection) {                    trace(collection+ " collection found");                    //store collection parent node                    var collection = gallery[i].childNodes;                    collectionInfo.text = collection.attributes.title;                    var totalItems = collection.childNodes.length;                    buildGallery(collection, totalItems);                    break;                } else if(i==gallery.length) {                    trace("Collection not found!");                    galleryInfo.text = "Not found";                    break;                }            }                    } else {            trace("Error loading XML file");        }    };    gallery_xml.load("gallery.xml");}

Node To Node Path Finding
Can anybody help me with this one. I had been looking for a tutorial that will find the shortest path from node to node. I have attached a sample picture to illustrate the problem.

I have created a symbol(dot) and name it pt01,pt02,pt03,pt04,pt05,and pt06. All I want is to find the shortest path from pt01 to pt06 and if ever it find the shortest path, it will draw a line from pt01,pt03,pt05 then pt06.

XML: Add Child Node To Existing Node
Hello all, just trying to get straight how this works.

Say I create some XML like so:

ActionScript Code:
var sample:XML = <sample>
<items>
</items>
</sample>


How would I now add an <item/> to the items elements? I've been trying to use

ActionScript Code:
sample.items.appendChild(<item/>);


but it hasn't seemed to work.

Any ideas? Thanks for reading.

-Dane

XML Element Node Vs Text Node
I have created an application via Flash/AS2 that is basically a form that updates a graphic based on the information given. I have those options saving into an XML file on the local hard drive at the location of the users choice. The problem I'm having is reading that XML file back in from the XML file (this was suppose to the the easy part).

Where I'm getting stuck is the NodeType... all my nodes are being typed as "1 - Element" so I can grab the nodeValue... instead it give me NULL.

My question is... did I code something wrong? is there a way to declare a node type?


ActionScript Code:
//SAMPLE XML
<?xml version='1.0' encoding='UTF-8' ?>
<allflex>
    <tag>
        <act>12345</act>
        <contact_name>Test XML</contact_name>
    <tag>
</allflex>

//ACTTIONSCRIPT 2.0
loadfile.onRelease = function () {
    var feed_xml:XML = new XML();
    feed_xml.ignoreWhite = true;
    feed_xml.onLoad = function(success:Boolean):Void {
        trace("onload...");
        if (success) {
            trace ("success...");
            var thePath_str:String = "/allflex/tag";
            var titleNode_str:Array = XPathAPI.selectNodeList(this.firstChild, thePath_str);
            trace(titleNode_str[0].firstChild.nodeType);

        }else{
            trace("error loading XML");
        }
    };
    feed_xml.load("C://xml.xml");
}

//OUTPUT
onload...
success...
1

This tells me I need to get the NodeType to a 3 - Text Node.

Any Information will be greatly appreciated.

Indexing A Node Below A Parent Node?
My problem: Attached within my node-hierarchies are text that I want to stay behind "sibling" node-hierarchies. Only solution I've found now is to attach the text to the root node, but then they loose their positional/scalar relationship to the node-hierarchies they're part of.


Are anyone aware about a solution to this problem?

Finding A Childs Name
I have a complex situation with some nested children and external movieclips
Basicly I have a Flash file which loads a accordion menu in a child, that accordion menu loads a external textfield.

Based on a buttonpress in the main flash file it has to load a textfile in the textfield in a flashfile loaded in the accordionmenu that resides in the main flash file

I've created a function in main.swf that sends which file to load. When I put the swf with the dynamic textfield in the root. It will load the text just fine. But when I put it in the accordion menu. I can't seem to find the correct path.


Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at info_fla::MainTimeline/frame1()
Main.swf
--container: Empty movieclip
-----menuloader:Loader (loads the accordion menu)
--------As3Accord.swf (empty flashfile with a document class attached
-------------As3Accord.as (the main menu class)
----------------Accordionmenu.as (menu class As3Accord.as references to)
----------------------contentholder: Empty movieclip (this is where the external swf's (menu items) will be loaded in
------------------------------info.swf (dynamic textfield)
----------------------------------tf: Textfield

I can refenence a function in main.swf from within info.swf by just saying parent.root["somefunction"](evt:Event) in info.swf

But how can find the correct path from within main.swf to the tf in info.swf

Code:
parent.root.container.menuloader.contentholder.tf.text = "test"
won't work (cant find the child).

due some circumstances I have to access it like this, I cant put the buttons in the info.swf they MUST be in main.swf

Is There A Way To Know How Many Childs Does A Movieclip Have?
Hi,

I would like to know if there's a way to know how many childs does a movieclip have.
For instance, it is possible to access each movie contained on another movieclip this way:

mainMC["submcName"]

but I need to go through each subMC:

for(i = 0; i < num_of_mcs_in_mainMC; i++) do something with mainMC[i];

Can anyone help me?

Various Amounts Of Childs?
Helloooooo!

Ok I know how much everyone hates XML questions, but I am stuck at one point!.

I have an xml being read into flash which I'm trying to parse correctly:


Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<client>
<clients>
<username>sauce</username>
<password>123</password>
<dates>
<notes>thumb1.jpg</notes>
<downloads>
<image>fdsfeeeesesess</image>
<image>fdsfeeeesesess</image>
<image>fdsfeeeesesess</image>
<image>fdsfeeeesesess</image>
</downloads>
</dates>
</clients>

<clients>
<username>jojopops</username>
<password>321</password>
<dates>
<notes>fdsdfs443s</notes>
<downloads>
<image>fdsfeeeesesess</image>
<image>fdsfeeeesesess</image>
</downloads>
</dates>
<dates>
<notes>f3333333s</notes>
<downloads>
<image>fds33gfgfess</image>
</downloads>
</dates>
</clients>
</client>
I know how to parse most of the data into flash ok, but I am stuck at this:

On the xml, you can see the following fields:

main child: clients
child data- username, password, dates.

The problem is that within dates, there is going to be a different amounts of childs for each <clients>.:

<dates>
<notes>test</notes> (can get this in ok)
the problem is here:
<downloads>
<image>test</image>
<image>test</image>
<image>test</image>
</downloads>

Basically, for each child, there is going to be various amounts of <image> tags. How can I read this into flash with a 'for' loop????

Childs In Midle (XML)
Hi,
I have an XML object in my flash (MX) project and I want to refence childs in the midle. I don't want a firschild or lastchild but a simple one betwin them.
I know that we can do a Array and next we use the "indice". But I want to know if the alternative is possible, working directely in XML nodes.

Thanks in advance

How To Acccess Childs?
Hello,

I have made a few movieclips on the stage with childs (non AS 3.0)
and now I would like to access these childs with the following script.


Code:
this.mcWebsiteNavigation.mcNavigationContact.addEventListener(MouseEvent.MOUSE_UP, showContact);

function showContact(eHandler:MouseEvent) {
var req:URLRequest = new URLRequest("http://blog.apsadvertising.nl/#movie");
navigateToURL(req, '_parent');
}
and now I get the following error


Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mcWebsiteClass/::frame60()
What am I doing wrong? I just made my move into AS 3.0 so I have got no clue.

Accessing Childs
Hi,

I have a little question, How can i access childs of objects in AS 3.0.

MovieClip _shape has 4 childs block1 ... block4

I used to be using this in AS 2.0, but it dosent work in AS 3.0 anymore, it says that it is undefined.


Code:
for(var i = 1; i < 5; i++){

doSomething(_shape["block"+i]);
}

Please, help me :]

thanks.

Button Childs Tweening
PHP Code:




var MainThumb:MovieClip = new MovieClip;
var ThumbImage:MovieClip = new MovieClip;
var ThumbBg:Shape;


ThumbBg = new Shape();
ThumbBg.graphics.beginFill(0xFF66FF);
ThumbBg.graphics.drawRect(0, 0, 150, 150);
ThumbBg.graphics.endFill();

addChild(MainThumb);        
MainThumb.addChild(ThumbBg);
MainThumb.addChild(ThumbImage);//

MainThumb.addEventListener(MouseEvent.ROLL_OVER, OverThumb);


function OverThumb(event:MouseEvent) {
   event.currentTarget.ThumbBg.alpha = 0.2;
   event.currentTarget.ThumbImage.alpha = 1;
}







anybody knows how can i tween the 2 childs( ThumbBg - ThumbImage) of the MainThumb button? looks so easy... but this doesnt work!

How To RemoveMovieClip All Childs From A Parent?
Is there a way to remove all child movie clips without doing child1.removeMovieClip(); for all child clips? Or I guess there isn't a method that does this, so, how would I cycle through each child mc?

Another question is, let's say I have a class that creates movie clips:

ActionScript Code:
class a{
   public function a (target:MovieClip){
      target.createEmptyMovieClip("child", blah)
   }
}

Then I use the class

ActionScript Code:
this.createEmptyMovieClip("parent", blah);
var childmaker:a = new a(parent);

So now I have a parent movie clip, and a child movie clip.
To remove the child movie clip, I would

ActionScript Code:
parent.child.removeMovieClip();

Now, the question is, do I also have to
delete childmaker;
so I won't be wasting memory?

So, 2 questions, how do I delete all children of a parent, and do I need to delete instances of the classes that are no longer needed?

Delete Childs Of A Movieclip
Hello everybody,
First post in this forum..So here we go:
How can i select some child clips, with let's say depth above from 5, and delete them?
Is it safe to overwrite a clip in the same depth instead of first deleting? Do i have memory leaks?

Thanx in advance...

Parent Gets Childs Attention?
I have an MC that contains a textField (that changes color when moused over). I make two instances of that MC and assign one to be the child of the other. Now when i mouseOver the child the parent changes color too... Is that normal? Is there a way to avoid it?


My MC is a custom class that extends MC and has a textField and eventListeners like:

ActionScript Code:
private function OverHandler(e:MouseEvent):void
        {
            e.currentTarget.titleLabel.textColor = mouseOverColor; //titleLabel is the textField
        }
private function OutHandler(e:MouseEvent):void
        {
            e.currentTarget.titleLabel.textColor = defaultColor;
        }

Call A Childs Function?
Hi everybody!

I got a little question about aprouching functions in childs..


ActionScript Code:
var np:Sprite = new Sprite;
            addChild(np);
           
            var photo1:newPhoto = new newPhoto(photoNumber);
            np.addChild(photo1);

In my newPhoto class/package I have a function but I can't aprouch it like this:

ActionScript Code:
np.photo1.myFunction();
I know it has to be something like this, cause I used this before:

ActionScript Code:
(np as MovieClip).myFunction();
But now I have to go trough 2 movieclips..

Anyone can explane me something about this?

Thanks!!

Parents, Childs And Frames
Hello all,

I am finding some difficulty in telling the child swf to inform the parent swf to gotoAndPlay its frame 2.

How could i possibly do this?

Removing All The Childs Of The Movieclip
Dear users.
In my document class I have assigned the root of fla to theRoot movieclip
as theRoot = MovieClip(this.root);
And as my program proceeds I have added several childs to theRoot.
Now at the end of my program I need to delete all the childs of theRoot.
So,how can I do this without individually deleting single childs.

Remove Childs, Only To Add Theme Later
I'm testing stuff to see if I can make my project complete...

is it possible to remove one movieclip, and then somehow later add it again?
I can remove an item easy
this.removeChild( this["firkant"] );

but how do I add it again?

Childs And Authoring Tool
If I make some graphics in a symbol that I export for AS and make a class for it, are those graphic objects accessible as childs?

How To Remove A Movieclip All Childs In AS 2.0?
there is no removeChild() in AS2.0, not sure how can I do this.

thanks in advance.

How To Search For Stage Childs By Code?
Hi,
I have this code:

stage.addChild(m1);
stage.addChild(m2);
stage.addChild(m3);
for each (var j:MovieClip in stage) {
trace(j.name);
}

but it dose not do anything, (I know I must do an if statement but it must trace first then I can search).

anybody can make this code work.

Thanks a lot.

How Do You Trace A Dynamicly Created Childs Name?
migrating from as2...new to as3, need to find out what would be the instance names of the following items (can't work this out.....doh!!!):


ActionScript Code:
//Imports needed for animation
import caurina.transitions.Tweener;
//XML file path
var xmlPath:String = "xml/site.xml";

//The XML data will be inserted into this variable
var settingsXML:XML;

//Array used for the tween so they won't get garbage collected
var tweensArray:Array = new Array();

// Load the XML file
var loader = new URLLoader();
loader.load(new URLRequest(xmlPath));
loader.addEventListener(Event.COMPLETE, xmlLoaded);

//This function is called when the XML file is loaded
function xmlLoaded(e:Event):void {

    //Make sure we're not working with a null loader
    if ((e.target as URLLoader) != null ) {
        //Insert the loaded data to our XML variable
        settingsXML = new XML(loader.data);
        settingsXML.ignoreWhitespace = true;
        //Call the function that creates the whole menu
        createMenu();
        trace(parent.height);
    }

}
function createMenu():void {
    //This will be used to represent a menu item
    var menuItem:MenuItem;
    //Counter
    var i:uint = 0;

    //Loop through the links found in the XML file
    for each (var link:XML in settingsXML.links.link) {

        menuItem = new MenuItem();

        //Insert the menu text (link.@name reads the link's "name" attribute)
        menuItem.menuLabel.text = link.@name;
        menuItem.projectTyp.text = link.@projectTyp;
        menuItem.client.text = link.@client;
        menuItem.dateTxt.text=link.@dateTxt;
        menuItem.xmlFile=link.@xmlFile;
        //If the text is longer than the textfield, autosize so that the text is
        //treated as left-justified text
        menuItem.menuLabel.autoSize = TextFieldAutoSize.LEFT;

        //Insert the menu button to stage
        menuItem.x = 0;
        menuItem.y = 0 + i*50;

        //Make the button look like a button (hand cursor)
        menuItem.buttonMode = true;
        menuItem.mouseChildren = false;

        //Add event handlers (used for animating the buttons)
        menuItem.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
        menuItem.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
        menuItem.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
        //attach the menu objects
        addChild(menuItem);
        //set the bg mc's bg to alpha=0;
        menuItem.bg.bg.alpha=0;
        //Increment the menu button counter, so we know how many buttons there are
        i++;

    }
}
//Function is called when the mouse is over a menu button
function mouseOverHandler(e:Event):void {

    //trace(e.target.name+" has been rolled over");
    Tweener.addTween(e.target.bg.bg,{alpha:1,time:0.25,transition:"easeOutLinear"});

}

//Function is called when the mouse moves out from the menu button
function mouseOutHandler(e:Event):void {
    /*Tween back original scale
     buttonTween = new Tween(e.target.bg, "scaleX", Elastic.easeOut, e.target.bg.scaleX, 1, 1, true);*/

    Tweener.addTween(e.target.bg.bg,{alpha:0,time:0.25,transition:"easeOutLinear"});

}


what the hell are these called (menuItem = new MenuItem())

trace(e.target.name) isn't right, cant work out what my mc's are called

How To Search For Stage Childs By Code?
Hi,
I have this code:

stage.addChild(m1);
stage.addChild(m2);
stage.addChild(m3);
for each (var j:MovieClip in stage) {
trace(j.name);
}

but it dose not do anything, (I know I must do an if statement but it must trace first then I can search).

anybody can make this code work.

Thanks a lot.

Use Childs Library (when Not Fully Loaded)
Hello everyone.
I have a question that is a bit tricky. Why I want to do this is becouse I need such a dynamic solution as posible with fast downloadtime.

- I have a host file that schould preload child files (this is to display what I can load visual).
- In the child files library i have a clip ready to be exportet (it's exported in first frame)
- when my host noticed that the childs second frame is loaded I want to grab the clip from the childs library and attach it in the host. (after this it will load nextone e.g.)

Why can I not get this to work
Is it not posible to get childrens exportet library clips? (have tried to load whole child clip before trying to grab the clip).

Best regards
//Bäcker

Adding And Removing Childs - How To Do It Safe
Hello Kirupa Forum,,

I got a problem with something, hope if someone know the awser.

I did a site navigation based on frames. When the site is on frame1, it addChild of a movieclip called 'mc'. But when I go to frame 2, I dont need mc anymore, so I call removeChild to remove the undesired mc. But when I go from another frame and step in frame 2 again, the mc does no exist and the code halts on the removeChild line. Someone have a good idea?

Use Childs Library (when Not Fully Loaded)
Hello everyone.
I have a question that is a bit tricky. Why I want to do this is becouse I need such a dynamic solution as posible with fast downloadtime.

- I have a host file that schould preload child files (this is to display what I can load visual).
- In the child files library i have a clip ready to be exportet (it's exported in first frame)
- when my host noticed that the childs second frame is loaded I want to grab the clip from the childs library and attach it in the host. (after this it will load nextone e.g.)

Why can I not get this to work
Is it not posible to get childrens exportet library clips? (have tried to load whole child clip before trying to grab the clip).

Best regards
//Bäcker

Incrementing ._rotation Value / Childs X Posotion
Ok so lets see if I can explain this correctly.

So I am making a movie rotate with action script

something like this in a onClipEvent(enterFrame){...

this.someMovie_mc._rotation += 1;


it is rotating fine... happy day, but now I need to figure out exactly how much the ._x ._y positiong is being effected on one of the children of someMovie_mc from the rotate.

the child of someMovie_mc._x value never changes when I rotate its parent because the actual x,y isnt being altered....

does that make sense? if so please please help!! thanks

Hard XML Read In. Random Number Of Childs.
How the hell would I read this XML into flash?

Code:
<XML>
<picture>
<title>ss</title>
<images>
<image>im1.jpg</image>
<image>im2.jpg</image>
<image>im13.jpg</image>
</images>
<desc>sssssss</desc>
<picture>

<picture>
<title>sssd</title>
<images>
<image>im33.jpg</image>
<image>im44.jpg</image>
</images>
<desc>sffss</desc>
<picture>
<XML>
I guess my question is that I know how to create a 'for' loop to read how many <picture> there are, but within each <picture> tag there are going to be different numbers of <image> tags.
Any ideas?

How Do I Create A Childs Function And OnEnterFrame Handler
I just dove into AS3 and the differences from AS2 are bigger than I thought they would be.

The thing I’ve been trying to figure out for two hours now is how to create functions and handle the event ENTER_FRAME in an added child (a MovieClip).

In AS2 you could write like this:

this.createEmptyMovieClip("mc1",1);
this.mc1.traceX = function(){
trace(this._x);
}
this.mc1.onEnterFrame = function(){
this.traceX();
}

How do I write this in AS3?

Thanks for helping!

Mind Map Web Application , Array Childs And GetChildIndex
Hi folks,

I wanted to make Mind Map web Application

just like this one http://www.bubbl.us

or this one http://www.mindomo.com/demo.htm

When I have start coding

I thought of making array of MovieClip to create boxes so I can select and deal with any box I wanted.

but I could'nt get the child index of the parent array so I can deal with it

also I want to select not the child only but the child inside the array child

that will be MovieClip Line so I connect it to the boxes


My code like this


ActionScript Code:
var container:Sprite = new Sprite();
var box:Array = new Array();
var mc:MovieClip = new MovieClip();

box[0] = createBox();
box[1] = createBox();
box[2] = createBox();

container.addChild(box[0]);
container.addChild(box[1]);
container.addChild(box[2]);
container.addChild(mc);

trace(container.getChildIndex(box[0]));
trace(container.getChildIndex(box[1]));
trace(container.getChildIndex(box[2]));
trace(container.getChildIndex(mc));

function createBox():MovieClip
{
    // Here will be the code that create 3 childs
    // 1 - graphics of the box
    // 2 - button create sub box with click event.
    // 3 - graphics of the line if it is sub box
    // and of course i will need to add some parameters in this function

    return this;
}

I thought the output will be like this

0
1
2
3

but it was like this

0
0
0
1

it deals with the array like it is one child

My Question is : how can I get the child index of the array

so I can deal with it or select it like when I start drag the box I change the line x and y that connected with other boxes to the new position using MOUSE_MOVE event.

I need for any help, and thank you very much.

Still Having Trouble Unloading Movies / Removing Childs
Hi, I've read several threads here regarding unloading movies and removing childs, but unfortunately I can't seem to get it to work in my code. I hope someone can please help.

I have 2 swfs that contain a music file: example.swf and example2.swf.
They are loaded by pressing button1 or button2 in my loader movie.
That works fine, but I keep adding new playing sounds to my stage when clicking each button instead of the sound switching from example.swf to example2.swf and vice versa.

The solution is container_mc.unload or removeChild(container_mc) but I've tried placing it everywhere but I keep getting different errors.

---------

ActionScript Code:
stop();

//the listener
button1.addEventListener(MouseEvent.CLICK, actie);


//the function 'actie'
function actie(event:MouseEvent):void{
gotoAndStop(2);
var container_mc:Loader = new Loader();
var urlrHome:URLRequest = new URLRequest("example.swf");
container_mc.load(urlrHome);
container_mc.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded);

function movieLoaded(event:Event):void
{

    addChild(container_mc);

}
}

//de listener
button2.addEventListener(MouseEvent.CLICK, actie2);


//de function 'actie2'
function actie2(event:MouseEvent):void{
gotoAndStop(1);
var container_mc:Loader = new Loader();
var urlrHome:URLRequest = new URLRequest("example2.swf");
container_mc.load(urlrHome);
container_mc.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded2);

function movieLoaded2(event:Event):void
{

addChild(container_mc);
}
}

Help is much appreciated

Dispatch An Event From Root Which Should Received By Childs.
Hi,

I have a class, which extends flash.display.Sprite.


Code:
package {
import flash.display.Sprite;
import flash.events.Event;

public class Circ extends Sprite {

public function Circ() {
init();
this.addEventListener("MainEvent", onMainEvent);
}
public function init():void {

var tmpCol:uint = Math.random()*16000000;
var tmpX:uint = Math.random()*400+50;
var tmpY:uint = Math.random()*200+50;

this.graphics.lineStyle(1);
this.graphics.beginFill(tmpCol);
this.graphics.drawCircle(tmpX, tmpY, 50);
this.graphics.endFill();
}
public function onMainEvent(e:Event):void {
trace("MainEvent occurs!");
}
}
}
These elements (Circ) will be added to the main timeline and should be listen
to the Event "MainEvent".
I will dispatch an event (flash.events.Event) from root which should be
received by every Circ instance (children of root) on the stage.


Code:
/**
* first frame timeline
*/
import flash.events.Event;

for (var i:uint = 0; i < 5; i++) {
this.addChild(new Circ());
}
this.dispatchEvent(new Event("MainEvent"));

I will that every Circ instance make the output "MainEvent occurs!".

But this doesn't work.
Could anyone help?

Handling MovieClip "childs" From An External AS File?
Hi everyone,
I have a MovieClip in my timeline which I want to associate to an external AS class file, let's say, MyButton.as. Inside this MovieClip there is a TextField which I want to be able to access from the ActionScript file.
I tried assigning an instance name to the TextField and creating an attribute in the MyButton.as class with that instance name, but it doesn't work.
Is there any way to do this? I guess I could create a new TextField in the MyButton.as constructor and add it to the display list of the class... but I would like to be able to manipulate it from the TimeLine.
Any ideas?
Thank you very much in advance.

LuTHieR

What Is The Name Of This Node?
Here is my XML code-


<cellPhoneText>

<downLoadRingToneText>TEXT</downLoadRingToneText>
<ringtoneText>RINGTONE</ringtoneText>
<youHaveSelectedText>YOU HAVE SELECTED:</youHaveSelectedText>
<previewText>PREVIEW</previewText>
<selectYourWirelessCarrierText>
<phone carriers="Carrier"></phone>
<phone carriers="Carrier"></phone>
<phone carriers="Carrier"></phone>
</selectYourWirelessCarrierText>


</cellPhoneText>

I need to know what the name of "selectYourWirelessCarrierText" is so I can call it from my flash file. I also need to know how to call it's childNodes as well.

Can anyone help? I posted this in the XML board as well but noone is on it.

XML Node Name
I attempted to find a previous forum for my problem, but I didn't find anything is explained by I sudden can't obtain the node name from my XML.

First this my XML file

Code:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<FLVCoreCuePoints Version="1">

<CuePoint>
<Time>1932</Time>
<Type>event</Type>
<Name>Marker 02</Name>
<Parameters>
<Parameter>
<Name>bullet</Name>
<Value></Value>
</Parameter>
</Parameters>
</CuePoint>

<CuePoint>
<Time>24544</Time>
<Type>event</Type>
<Name>Marker 01</Name>
<Parameters>
<Parameter>
<Name>bullet</Name>
<Value></Value>
</Parameter>
</Parameters>
</CuePoint>

</FLVCoreCuePoints>


And I want to pull it in and store in an Object/Array. It seemed like an easy assignment when I started, but I can't get the node names and that is an important part. I can't reformat the XML file as it is published by another program, so I need to import as is. Here is my XML Loader class.


Code:
package pageComponents.soundComp
{
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;

public class CueXML
{
private var filename:String;
private var xml:XML;
private var xmlList:XMLList;
private var XMLData:Object;

private var tempArr:Array;

public function CueXML(pFilename:String)
{
filename = pFilename;

XMLData = new Object();
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest(filename));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
}

public function xmlLoaded(e:Event):void
{
xml = XML(e.target.data);
var a:int;
var b:int;
xmlList = xml.children();

tempArr = new Array();

for(a=0; a < xmlList.length(); a++)
{
tempArr.push(new Object());
var xmlcue = xmlList[a].children();

for(b=0; b < xmlcue.length(); b++)
{
var xmlChild = xmlcue[b];
trace(xmlChild.node.nodeName);
}

}
}

}


What am I missing, why can't I see the node name?

Samac

Getting An XML Node Into A Var
Hi, I have a datagrid called dg that has data populated to it thru an external XML. What I am trying to achieve is whenever someone clicks on an item in the grid it stores that items coordinates to a variable called locCoordinates. At this moment it is tracing out the coordinates for all of the items in the grid. I just dont know how to go about only getting the selected items coordinates. Any help is appreciated. I attached a sample of my XML and my AS3 code.

Thanks

XML Snippet

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<Placemark>
<description>Location Name</description>
<LookAt>
<longitude>-80.08228780449664</longitude>
<latitude>26.76333909302779</latitude>
<altitude>0</altitude>
<range>800531.7783723106</range>
<tilt>0.2434603296494301</tilt>
<heading>2.751823574569335</heading>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
<styleUrl>#msn_mechanic1</styleUrl>
<Point>
<coordinates>-80.08228780449664,26.76333909302779</coordinates>
</Point>
</Placemark>



AS3 Code

Code:
//Packages
import com.afcomponents.umap.core.UMap;
import com.afcomponents.umap.providers.google.GoogleProvider;
import com.afcomponents.umap.types.LatLng;
import com.afcomponents.umap.overlays.KMLLayer;
import com.afcomponents.umap.styles.MarkerStyle;
import com.afcomponents.umap.styles.GeometryStyle;
import com.afcomponents.umap.display.markermanager.MarkerManager;
import com.afcomponents.umap.display.markermanager.ExpandedGroupPattern;
import com.afcomponents.umap.overlays.Marker;
import com.afcomponents.umap.overlays.Layer;
import com.afcomponents.umap.interfaces.IOverlay;
import com.afcomponents.umap.events.OverlayEvent;
map.addControl(ZoomControl);
map.addControl(MapType);
map.addControl(PositionControl);

//Set Map Provider

var settings:URLRequest = new URLRequest("http://umap.s3.amazonaws.com/assets/xml/GoogleSettings.xml?rand=" + Math.random());
var language:URLRequest = new URLRequest("http://maps.google.com/maps?file=api&v=2");
var copyright:URLRequest = new URLRequest("http://www.afcomponents.com/proxy/g_map_as3/copyright.php");
map.setProvider(new GoogleProvider(false, settings, language, copyright));

//Create Layers - Load KML Points - Center/Set Map Zoom

var theKml:KMLLayer = new KMLLayer();
theKml.load("MarooneServiceCenters.kml");
theKml.addEventListener(Event.COMPLETE, theKmlComplete);
map.addOverlay(theKml);
function theKmlComplete(e:Event):void {
theKml.addEventListener(OverlayEvent.READY, ready);

function ready(event) {

// change icons for loaded markers

var style:Object = {icon:"wrenchmarker.gif"};
applyStyleToMarkers(theKml, style);
}

function applyStyleToMarkers(layer:Layer, style:Object) {

for each (var overlay:IOverlay in layer.getOverlays()) {
if (overlay is Marker) {
overlay.setStyle(style);
} else if (overlay is Layer) {
applyStyleToMarkers(Layer(overlay), style);
}
}
}
map.setCenter(new LatLng(26.210,-80.220),9);
}

var myXML:XML = new XML();
myXML.ignoreWhite = true;
var XML_URL:String = "MarooneServiceCenters.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", parseXML);

//Loads Datagrid with Locations

function parseXML(e:Event):void {

myXML = new XML(e.target.data);
for (var i:int = 0; i <myXML.*.length(); i++) {
dg.addItem({Locations:myXML.Placemark.description.text()[i]});
dg.addEventListener(MouseEvent.CLICK, locSelect);
}
//Loads Location Coordinates into Var

function locSelect(e:Event):void {

var locCoordinates = int;
locCoordinates = (myXML.Placemark.Point.coordinates);
trace(locCoordinates);
}
}

Which Node?
<Result><Item>
<Index>a</Index>
</Item> <Item>
<Index>b</Index>
</Item><Item>
<Index>c</Index>
</Item></Result>

myxml = new xml;

How to find the item b's item number. Meaning i want to get the node number 1.

Thanks

XML Node
hey there... long time "reader", first time "poster"

if I have this

Code:
<visiting-team><team-name name="TEAM NAME" alias="TN"/>
<team-city city="CITY"/>
<team-code id="5"/>
<record wins="9" losses="6" ties="0" pct=".600"/></visiting-team>
and this works for me in AS (I didn't post the whole xml file, childNode[9] is <visiting-team>)


Code:
visitingTeam[i] = xmlNode.childNodes[i].childNodes[9].firstChild.attributes["alias"];
is there no way to reference the node by name? i.e.

Code:
visitingTeam[i] = xmlNode.childNodes[i].childNodes["visiting-team"].firstChild.attributes["alias"];
I've tried the above and it does not work... but you see what I mean. Do you HAVE to reference the nodes by number and not name?

Basically.. the problem I'm having is sometimes my <visiting-team> is childNode[9] and sometimes it's childNode[12] (depending on if the game is currently being played or not). So instead of having 'basically' the same code in a few "if" loops.. I was hoping there was a way to get the value by name instead of number.

thanks

Trying To XML Node Value Only If Node Has A Value?
Hi,

I am bringing in values from XML nodes, and in-turn attaching a MovieClip in a loop;

however the ones that are undefined purposely, are still attaching clips

Is there a way to stop this, currently i'm testing with:


Code:
test = DJThumbs[i].childNodes[0].nodeValue
if (test != ""){
trace(test)
}
thanks

How Do You Get The Name Of An XML Node?
I'm looping through an XMLList and I want get the name of the current node that I'm looking at? I can't seem to find a method that does this?

The XML looks something like this:


PHP Code:



<p x="18" y="171"/><p x="18" y="172"/><p x="18" y="173"/><move/><p x="19" y="165"/><p x="20" y="165"/> 




I want to check whether the tag in is a p or a move tag. In AS2 there was the nodeName property. I can't seem to find an equivalent in AS3.

Xml & Add Node
Hello,

I have a xml file MyXML:
<Myxml>
<mytext>ABCD</mytext>
<mytext>EFGH</mytext>
<mytext>IJKL</mytext>
</Myxml>

I want to random and extent the content, but fail, please help. The problem is don't know how to
make a new xml doc from the origin doc.

doc = new XML();
doc.ignoreWhite = true;
doc.onLoad = isLoaded;
doc.load("MyXML.xml");

function isLoaded(success)
{
_l2 = this;
var my_xml = new XML();
var ary = new Array();
for (j = 0; j < 10; ++j) {
for (i = 0; i < _l2.firstChild.childNodes.length; ++i) ary = i;
ary.sort( function() { return random(2)? 1 : -1; });

for (i = 0; i < ary.length; ++i) {
var node = _l2.childNodes.cloneNode(true);
my_xml.appendChild(node);
}
}
}
this = nothing;
this = my_xml;
}

XML Node Value
I'm going after the Yahoo weather and trying to get the value of a XML node

So after I grab the node

item_buildNode.toString() = <lastBuildDate>Tue, 26 Dec 2006 12:51 pm CST</lastBuildDate>

So I know I have the proper node

But I want just the value without the tags

If I try item_buildNode..nodeValue, That returns null

Can I just get the value? If so, how?


Thanks
Mathias

XML Node
Hi all. I changed the sctructure of my XML but i can't load it. I post the 2 methods.

1º - WORK VERSION

HTML Code:
XML
<?xml version="1.0" encoding="UTF-8"?>
<fotos>
<foto fp="img1.jpg" fg="img1.jpg" categoria="img1.jpg"/>
<foto fp="imgs/foto2p.jpg" fg="imgs/foto2g.jpg"categoria="teste2"/>
<foto fp="imgs/foto3p.jpg" fg="imgs/foto3g.jpg"categoria="teste3"/>
<foto fp="imgs/foto1p.jpg" fg="imgs/foto1g.jpg"categoria="teste3"/>
<foto fp="imgs/foto2p.jpg" fg="imgs/foto2g.jpg"categoria="teste3"/>
<foto fp="imgs/foto3p.jpg" fg="imgs/foto3g.jpg"categoria="teste3"/>
<foto fp="imgs/foto1p.jpg" fg="imgs/foto1g.jpg"categoria="teste3"/>
<foto fp="imgs/foto2p.jpg" fg="imgs/foto2g.jpg"categoria="teste3"/>
<foto fp="imgs/foto3p.jpg" fg="imgs/foto3g.jpg"categoria="teste3"/>
<foto fp="imgs/foto1p.jpg" fg="imgs/foto1g.jpg"categoria="teste3"/>
<foto fp="imgs/foto2p.jpg" fg="imgs/foto2g.jpg"categoria="teste3"/>
<foto fp="imgs/foto3p.jpg" fg="imgs/foto3g.jpg"categoria="teste3"/>
</fotos>

FLASH
dados = this.firstChild.childNodes
1º - NOT WORK VERSION

HTML Code:
XML
<?xml version="1.0"?>
<item>
<modelo>
<titulo> CAFETEIRAS</titulo>
<url>imagens/56870.jpg</url>
<url2>cafeteiras.xml</url2>
</modelo>
<modelo>
<titulo> CHALEIRAS</titulo>
<url>imagens/53783.jpg</url>
<url2>chaleiras.xml</url2>
</modelo>
<modelo>
<titulo> TORRADEIRAS</titulo>
<url>imagens/78012.jpg</url>
<url2>torradeiras.xml</url2>
</modelo>
<modelo>
<titulo> LIQUIDIFICADOR</titulo>
<url>imagens/6550.jpg</url>
<url2>liquidificador.xml</url2>
</modelo>
<modelo>
<titulo> PANELAS PARA FOUNDUE</titulo>
<url>imagens/88533.jpg</url>
<url2>fondue.xml</url2>
</modelo>
<modelo>
<titulo> PANELA SLOW COOKER</titulo>
<url>imagens/85146.jpg</url>
<url2>slow.xml</url2>

</modelo>
<modelo>
<titulo> JARRAS TÉRMICAS</titulo>
<url>imagens/5817.jpg</url>
<url2>grelhar.xml</url2>
</modelo>
</item>


FLASH
????? HOW I CAN LOAD IT?!?!?

Anyone Know How To Add New Node To XML With AS
I want to add new node to the current XML file.
It already contain some data and I want to add new node with Flash.
I know how to retrieve the data but don't know how to insert

Copyright © 2005-08 www.BigResource.com, All rights reserved