如何使用 ActionScript 2.0 从不同的框架调用函数?
我正在寻找一种方法来调用 ActionScript 2.0 中不同框架中定义的函数。详细信息如下:
作为第 1 帧中的按钮事件,我有:
on (release)
{
_root.gotoAndStop(2); //Going to Frame 2.
selectVideo(5); //Calling a function defined in Frame 2.
//Calling this function is not working in the way i wrote it above.
}
在第 2 帧上,我在框架本身上有以下脚本:
var vlist:XML = new XML(); //Creating an XML variable
vlist.ignoreWhite = true; //Ignoring the white spaces in the xml
vlist.load("videoList.xml"); //Loading a list of videos from the xml.
vlist.onLoad = function()
{
var videos:Array = this.firstChild.childNodes;
for (i = 0; i < videos.length; i++)
{
vidList.addItem({label:videos[i].attributes.desc, data:videos[i].attributes.url});
}
vid.load(vidList.getItemAt(0).data);
vidList.selectedIndex = 0;
//Notes:
//vid: is an instance of (FLVPlayback) component.
//vidList: is an instance of a (List) component.
};
function selectVideo(index:Number)
{
//Here is the function that i want to call from frame 1 but it is not getting called.
vidList.selectedIndex = index;
}
var listHandler:Object = new Object();
listHandler.change = function(evt:Object)
{
vid.load(vidList.getItemAt(vidList.selectedIndex).data);
};
vidList.addEventListener("change",listHandler);
由于某种原因,第 2 帧上的代码本身可以工作,但从另一个帧的列表中选择索引不起作用。换句话说,我无法从第 1 帧成功调用 selectVideo()
,而它是在第 2 帧中定义的。
正如所暗示的,该程序的目标是引用列表中的某个视频来自不同的框架。整个代码工作正常,没有错误,我只是无法从列表中选择视频并播放它(如果它最初位于不同的前一帧中)。
任何想法、建议或解决方案都将受到高度赞赏! 预先感谢您的帮助!
I am looking for a way to call a function defined in a different frame in ActionScript 2.0. The details are as follows:
As a button event in frame 1, I have:
on (release)
{
_root.gotoAndStop(2); //Going to Frame 2.
selectVideo(5); //Calling a function defined in Frame 2.
//Calling this function is not working in the way i wrote it above.
}
On Frame 2, I have the following script on the frame itself:
var vlist:XML = new XML(); //Creating an XML variable
vlist.ignoreWhite = true; //Ignoring the white spaces in the xml
vlist.load("videoList.xml"); //Loading a list of videos from the xml.
vlist.onLoad = function()
{
var videos:Array = this.firstChild.childNodes;
for (i = 0; i < videos.length; i++)
{
vidList.addItem({label:videos[i].attributes.desc, data:videos[i].attributes.url});
}
vid.load(vidList.getItemAt(0).data);
vidList.selectedIndex = 0;
//Notes:
//vid: is an instance of (FLVPlayback) component.
//vidList: is an instance of a (List) component.
};
function selectVideo(index:Number)
{
//Here is the function that i want to call from frame 1 but it is not getting called.
vidList.selectedIndex = index;
}
var listHandler:Object = new Object();
listHandler.change = function(evt:Object)
{
vid.load(vidList.getItemAt(vidList.selectedIndex).data);
};
vidList.addEventListener("change",listHandler);
For some reason, the code on frame 2 is working by itself but selecting an index from the list from another frame is not working. In other words, I am not able to successfully call selectVideo()
from frame 1 while it is defined in frame 2.
The objective of the program, as implied, is referring to a certain video from the list from a different frame. The whole code is working without errors, I'm just not able to select a video from the list and play it if it was initially in a different previous frame.
Any ideas, suggestions or solutions are highly appreciated!
Thanks in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一:时间线脚本一团糟,尝试使用类代替。
您可以尝试在
_root
上设置一个变量。类似_root.nextIndex = 5;
的内容,然后将框架更改为 2。然后调用该函数并向其传递
_root.nextIndex
或完全删除该函数,然后执行以下操作 任何函数的外部。
first: timeline scripting is a mess, try using classes instead.
you could try and set a variable on
_root
. something like_root.nextIndex = 5;
and then change the frame to 2.then either call the function and pass it the
_root.nextIndex
or remove the function completely and just do theoutside of any function.
这是对您的代码的快速修复(您缺少 _root 来访问函数调用的主时间轴):
但我会尝试遵循 pkyeck 的建议并尝试限制添加在时间轴中不同帧上的脚本,因为它可以变得非常混乱。
This is the quick fix for your code (you were lacking the _root to access the main timeline on the function call):
But I would try to follow pkyeck's advice and try to limit the script added on different frames in the timeline, as it can get really messy.