Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » Flash - ActionScript

Giving Links To Dynamically Created MC

 
Jump to:  
 
system_critical55
PostPosted: Tue Sep 02, 2008 2:51 am    Post subject: Giving Links To Dynamically Created MC
       
Hi, I've been working on a semi-dynamic portfolio for my personal work. It
combines a .swf and an XML file to create a bunch of little boxes, containing
thumbnails, images, and links, all dynamically generated. Everything works fine
except the link. Here is the ActionScript:


[h]var boxes = new Array();
var myXml = new XML();
boxY = 30;
myXml.ignoreWhite = true;
myXml.load("../xml/projects.xml");
myXml.onLoad = function() {
for (var i = 0; i<this.firstChild.childNodes[1].childNodes.length; i++) {
_root.attachMovie('projectBox','box'+i,i,{_y:boxY});
boxes.push(_root['box'+i]);
boxY = boxY+45;
boxes[i].projectName.text =
myXml.firstChild.childNodes[1].childNodes[i].attributes.pTitle;

boxes[i].thumb.loadMovie(myXml.firstChild.childNodes[1].childNodes[i].attribut
es.thumb);
boxes[i].projectBtn.onRelease = function() {
getURL(myXML.firstChild.childNodes[1].childNodes[i].attributes.link); //
CONSOLE SAYS UNDEFINED
};
}
};[/h]

Here is the XML:


[h]<?xml version="1.0" encoding="UTF-8"?>

<projects>

<websites>
<project pTitle="Olde Oaks Golf Club" link="#" thumb="../img/oaks.gif" />
</websites>

<films>
<project pTitle="Trans/mission"
link="http://www.westwardmotion.com/projects/films/transmission.html"
thumb="../img/transmission.jpg" />
</films>

<Writings>
<project pTitle="Coming Soon" link="#" thumb="../img/placeholder.jpg"/>
</Writings>

</projects>[/h]

I think the problem with the getURL() is that the variable i from the for loop
changes several times, while the getURL() occurs on with the onClick function.
Perhaps at the time of the onClick the variable is undefined. Is there a
solution to give these buttons dynamic links? Thanks for helping a noob. It is
very much appreciated.
 

 
Nitin
PostPosted: Tue Sep 02, 2008 4:21 am    Post subject: Re: Giving Links To Dynamically Created MC
       
Hi,

Use this way..
It works fine..

var boxes = new Array();
var myXml = new XML();
var links = new Array();
boxY = 30;
myXml.ignoreWhite = true;
myXml.load("projects.xml");
myXml.onLoad = function() {
for (var i = 0;
i<this.firstChild.childNodes[1].childNodes.length; i++) {
_root.attachMovie("projectBox","box"+i,i,{_y:boxY});
boxes.push(_root["box"+i]);
boxY = boxY+45;
boxes[i].projectName.text myXml.firstChild.childNodes[1].childNodes[i].attributes.pTitle;
boxes[i].thumb.loadMovie(myXml.firstChild.childNodes[1].childNodes[i].attributes.thumb);
links.push(myXml.firstChild.childNodes[1].childNodes[i].attributes.linkname)
boxes[i].projectBtn.onRelease = function() {
linkid = String(this._parent).substr(-1,2);
getURL(links[linkid])
};
}
};


----------------------------
Nitin
FlashScriptor (IBM)


On Sep 2, 7:51 am, "system_critical55" <webforumsu...@macromedia.com>
wrote:
Quote:
Hi, I've been working on a semi-dynamic portfolio for my personal work. It
combines a .swf and an XML file to create a bunch of little boxes, containing
thumbnails, images, and links, all dynamically generated. Everything works fine
except the link. Here is the ActionScript:

 [h]var boxes = new Array();
 var myXml = new XML();
 boxY = 30;
 myXml.ignoreWhite = true;
 myXml.load("../xml/projects.xml");
 myXml.onLoad = function() {
        for (var i = 0; i<this.firstChild.childNodes[1].childNodes.length; i++) {
                _root.attachMovie('projectBox','box'+i,i,{_y:boxY});
                boxes.push(_root['box'+i]);
                boxY = boxY+45;
                boxes[i].projectName.text > myXml.firstChild.childNodes[1].childNodes[i].attributes.pTitle;

                boxes[i].thumb.loadMovie(myXml.firstChild..childNodes[1].childNodes[i].attri­but
es.thumb);
                boxes[i].projectBtn.onRelease = function() {
                getURL(myXML.firstChild.childNodes[1].childNodes[i].attributes.link); //
CONSOLE SAYS UNDEFINED
                };
        }
 };[/h]

 Here is the XML:

 [h]<?xml version="1.0" encoding="UTF-8"?

 <projects

        <websites
 <project pTitle="Olde Oaks Golf Club" link="#" thumb="../img/oaks.gif" /
        </websites

        <films
 <project pTitle="Trans/mission"
link="http://www.westwardmotion.com/projects/films/transmission.html"
thumb="../img/transmission.jpg" /
        </films

        <Writings
 <project pTitle="Coming Soon" link="#" thumb="../img/placeholder..jpg"/
        </Writings

 </projects>[/h]

 I think the problem with the getURL() is that the variable i from the for loop
changes several times, while the getURL() occurs on with the onClick function.
Perhaps at the time of the onClick the variable is undefined. Is there a
solution to give these buttons dynamic links? Thanks for helping a noob. It is
very much appreciated.
 

 
kglad
PostPosted: Tue Sep 02, 2008 5:24 am    Post subject: Re: Giving Links To Dynamically Created MC
       
use the attach code option to display code in this forum.

and use a property of _root["box"+i] to reference the value i, so that box
knows it's the ith box. i like to use ivar:

_root["box"+i].ivar = i;

you can then reference this.ivar in your onRelease to retrieve the value i.
 

 
system_critical55
PostPosted: Wed Sep 03, 2008 2:47 am    Post subject: Re: Giving Links To Dynamically Created MC
       
Hi,

Thank you very much for your help. I tried using _root["box"+i].ivar = i; to
declare a top level variable holding the contents of i, but the onRelease still
yields undefined output. I probably put it in the wrong place. I understand a
top level variable to hold the contents of i is necessary, but I'm not sure
where or how to declare it. I'm still quite the scripting novice. Thank you
very very much for you time, patience, and help.
 

 
system_critical55
PostPosted: Wed Sep 03, 2008 2:47 am    Post subject: Re: Giving Links To Dynamically Created MC
       
Hi,

Thank you very much for your help. I tried using _root["box"+i].ivar = i; to
declare a top level variable holding the contents of i, but the onRelease still
yields undefined output. I probably put it in the wrong place. I understand a
top level variable to hold the contents of i is necessary, but I'm not sure
where or how to declare it. I'm still quite the scripting novice. Thank you
very very much for you time, patience, and help.

var boxes = new Array();
var myXml = new XML();
boxY = 30;
myXml.ignoreWhite = true;
myXml.load("../xml/projects.xml");
myXml.onLoad = function() {
for (var i = 0; i<this.firstChild.childNodes[1].childNodes.length; i++) {
_root.attachMovie('projectBox','box'+i,i,{_y:boxY});
_root["box"+i].ivar = i;// IM PROBABL PUTTING THIS IN THE WRONG PLACE.
boxes.push(_root['box'+i]);
boxY = boxY+45;
boxes[i].projectName.text =
myXml.firstChild.childNodes[1].childNodes[i].attributes.pTitle;

boxes[i].thumb.loadMovie(myXml.firstChild.childNodes[1].childNodes[i].attribut
es.thumb);
boxes[i].projectBtn.onRelease = function() {

trace(myXML.firstChild.childNodes[1].childNodes[ivar].attributes.link);//
STILL YIELDS UNDEFINED.
};
}
};
 

 
kglad
PostPosted: Wed Sep 03, 2008 3:46 am    Post subject: Re: Giving Links To Dynamically Created MC
       
:



var boxes = new Array();
var myXml = new XML();
boxY = 30;
myXml.ignoreWhite = true;
myXml.load("../xml/projects.xml");
myXml.onLoad = function() {
for (var i = 0; i<this.firstChild.childNodes[1].childNodes.length; i++) {
_root.attachMovie('projectBox','box'+i,i,{_y:boxY});
_root["box"+i].ivar = i;// IM PROBABL PUTTING THIS IN THE WRONG PLACE.
boxes.push(_root['box'+i]);
boxY = boxY+45;

_root["box"+i].projectName.text =
myXml.firstChild.childNodes[1].childNodes[i].attributes.pTitle;

_root["box"+i].thumb.loadMovie(myXml.firstChild.childNodes[1].childNodes[i].at
tributes.thumb);
_root["box"+i].projectBtn.onRelease = function() {


trace(myXML.firstChild.childNodes[1].childNodes[this._parent.ivar].attributes
..link);// STILL YIELDS UNDEFINED.
};
}
};
 

 
system_critical55
PostPosted: Wed Sep 03, 2008 5:44 pm    Post subject: Re: Giving Links To Dynamically Created MC
       
Hi, Thanks again for the help. For some reason the above code still outputs
undefined for ivar. It could be my somewhat buggy combination of CS3 and OSX
Leopard, which has caused me problems before. Any more
suggestions? Thanks.
 

 
kglad
PostPosted: Wed Sep 03, 2008 11:35 pm    Post subject: Re: Giving Links To Dynamically Created MC
       
are your textfields populated with the correct text? if so, try the following
and click on a button:



_root["box"+i].projectBtn.onRelease = function() {
trace(this._parent+" : "+this._parent.ivar);

trace(myXml.firstChild.childNodes[1].childNodes[this._parent.ivar].attributes.pT
itle);
};
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

wózki widłowe Tłumacz niemiecki Tłumacz zabawki rowery