all groups > flash actionscript > october 2006 >
You're in the

flash actionscript

group:

XML Array 'Undefined' Inside A Function


XML Array 'Undefined' Inside A Function KTULKevin
10/19/2006 9:59:16 PM
flash actionscript: I've been working on a flash video player in which icons float in a circular
motion around a large video window. When you click on one of the floating
icons, I want that video to play in the large window. The whole thing reads
from an xml file to get the images inside the icons as well as what videos to
play:

<icons>
<icon image="icon1.jpg" url="promo1.flv" />
<icon image="icon2.jpg" url="promo2.flv" />
AND SO ON.....
</icons>

The attached actionscript below is giving me a problem. Everything loads fine
and looks great. The image attribute works fine. But, when you get down to the
part where it says ns.play("http://......, in the testing phase it gives me
"Error opening URL "http://www.ktul.com/static/videos/undefined"". I'm sure
it's because it's inside a function. But, I don't know what I can do to make it
work. You can view this thing in action at
http://www.ktul.com/static/newcarousel.swf.. Any ideas?

Thanks
Kevin

var numOfItems:Number;
var radiusX:Number = Stage.width/2;
var radiusY:Number = Stage.height/4;
var centerX:Number = Stage.width/2;
var centerY:Number = Stage.height/1.6;
var speed:Number = 0.05;
var perspective:Number = 130;
var home:MovieClip = this;

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
theVideo.attachVideo(ns);
ns.play("http://www.ktul.com/static/videos/promo.flv");

var xml:XML = new XML();
xml.ignoreWhite = true;

xml.onLoad = function()
{
var nodes = this.firstChild.childNodes;
numOfItems = nodes.length;
for (var i=0;i<numOfItems;i++)
{
var t = home.attachMovie("item","item"+i,i+1);
t.angle = i * ((Math.PI*2)/numOfItems);
t.onEnterFrame = mover;
t.icon_mc.loadMovie("http://www.ktul.com/static/"+nodes[i].attributes.image);
t.onPress = function()
{
ns.play("http://www.ktul.com/static/videos/"+nodes[i].attributes.url);
}
}
}

xml.load("http://www.ktul.com/static/icons.xml");


function mover()
{
this._x = Math.cos(this.angle) * radiusX + centerX;
this._y = Math.sin(this.angle) * radiusY + centerY;
var s:Number = this._y / (centerY+radiusY);
this._xscale = this._yscale = s*80;
this.angle += this._parent.speed;
this.swapDepths(Math.round(this._xscale) + 100);
}

this.onMouseMove = function()
{
speed = (this._xmouse-centerX)/4500;
}
Re: XML Array 'Undefined' Inside A Function NSurveyor
10/19/2006 10:37:46 PM
First, since nodes is a local variable to the onLoad handler, you won't be able
to reference it inside the onPress handler. Also, the value of i is not kept at
the value it was when that icon clip was being created, ie it will be at
numOfItems by the time you click on any icon. A simple remedy is to make the
icon clip *know* it's corresponding URL:

t.url = nodes[i].attributes.url;
t.onPress = function()
{
ns.play("http://www.ktul.com/static/videos/"+this.url);
}
Re: XML Array 'Undefined' Inside A Function KTULKevin
10/19/2006 11:24:17 PM
AddThis Social Bookmark Button