好吧,我不知道我是怎么做到的,可能是AS3众神在我编码之后我的滚动条工作时对我很生气,没有错误。但我有一个非常奇怪的问题。我有三个不同的按钮,它们没有相互嵌套,并且它们具有用于调用函数的鼠标单击的事件监听器。每当点击这三个按钮中的一个时,它就会调用它应该具有的功能以及来自swf生命周期的所有前一个按钮。我不知道这是怎么回事,说实话我很震惊,我,我感到震惊。这是怎么回事?是eventListeners的东西?也许是URLLoader的东西?我不知道,我已经追踪到了每一步,我什么也没有,所以我把自己扔到了更聪明的程序员面前,希望你们中的一位尊敬的绅士和绅士知道我做错了什么,请怜悯一个可怜的程序员的灵魂。
文档类文件 Pastie
package {
import gs.TweenMax;
import gs.easing.*;
import flash.display.*;
import flash.events.*;
import flash.ui.Keyboard;
import flash.net.*;
import flash.external.ExternalInterface;
import FullScreenScrollBar;
public class Gessner extends MovieClip {
//====================================Declare Variables================================//
var objectsArray:Array = ["whatwedo_bkg", "whoweare_bkg", "howmuch_bkg", "needsome_bkg"];
var images:Array = [];
var instances:Array = [];
var imageInstances:Array = [];
var paginationButtons:Array =[];
//=====================================================================================//
private var xmlLoader:URLLoader = new URLLoader();
private var xmlData:XML = new XML();
//======================================================================================
public function initXML(e:Event) {
//======================================================================================
var target:String = e.currentTarget.name;
if (e.currentTarget.name == "recent_projects" || e.currentTarget.name == "whoweare") {
xmlLoader.addEventListener(Event.COMPLETE, onCompleteXML);
xmlLoader.load(new URLRequest("http://www.gessnerengineering.com/projects"));
} else if (e.currentTarget.name == "our_staff") {
xmlLoader.addEventListener(Event.COMPLETE, onCompleteXML);
xmlLoader.load(new URLRequest("http://www.gessnerengineering.com/profiles"));
}
//========================================================================
function onCompleteXML(e:Event):void {
//========================================================================
xmlData = new XML(e.currentTarget.data);
makePagination();
trace("onCompleteXML() target: " + target);
if (target == "recent_projects" || target == "whoweare") {
trace("loadProjectXML() got called from onCompleteXML();");
loadProjectsXML(0, xmlData);
} else if (target == "our_staff") {
loadStaffXML(0, xmlData);
}
}
//========================================================================
function makePagination():void {
//========================================================================
var pages:Number;
trace("makePagination() target: " + target);
if (target == "recent_projects" || target == "whoweare") {
pages = Math.ceil(xmlData.project.length() / 13);
} else if (target == "our_staff") {
pages = Math.ceil(xmlData.profile.length() / 13);
}
for (var i:Number = 0; i < pages; i++) {
var tmp:pageNum = new pageNum();
var startX:Number = -(((pages * 50) - 10) / 2);
tmp.Id = i * 13;
tmp.x = startX;
startX += 50;
tmp.y = 0;
tmp.label.text = String(i+1);
tmp.buttonMode = true;
tmp.mouseChildren = false;
tmp.useHandCursor = true;
tmp.addEventListener(MouseEvent.CLICK, onChangePage);
Gessner(root).pages.whoweare_bkg.pagination.addChild(tmp);
paginationButtons.push(Gessner(root).pages.whoweare_bkg.pagination.getChildByName(tmp.name));
}
}
//========================================================================
function onChangePage (e:MouseEvent):void {
//========================================================================
if (target == "recent_projects" || target == "whoweare") {
trace("loadProjectXML() got called from onChangePage();");
loadProjectsXML(e.currentTarget.Id as Number, xmlData);
} else {
loadStaffXML(e.currentTarget.Id as Number, xmlData);
}
}
}
//======================================================================================
public function loadProjectsXML(startNum:Number, xmlData:XML):void {
//======================================================================================
removeAll();
var index:int = 1;
var endNum:Number = startNum + 13;
if (endNum > xmlData.project.length()) {
endNum = xmlData.project.length();
//trace("projectENDNUM" + endNum);
}
for(startNum; startNum < endNum; startNum++) {
var instance:String = "cont" + index;
var imageURL:String = "http://www.gessnerengineering.com/system/files/" + xmlData.project[startNum].assets.asset[0]["id"] + "/thumb/" + xmlData.project[startNum].assets.asset[0]["file-file-name"];
loadImage(imageURL, instance);
Gessner(root).pages.whoweare_bkg[instance].title.text = xmlData.project[startNum].name;
Gessner(root).pages.whoweare_bkg[instance].description.text = xmlData.project[startNum].description;
instances.push(instance);
index++;
}
}
//=======================================================================================
public function loadStaffXML(startNum:Number, xmlData:XML):void {
//=======================================================================================
removeAll();
var index:int = 1;
var endNum:Number = startNum + 13;
if (endNum > xmlData.profile.length()) {
endNum = xmlData.profile.length();
////trace("endNUM" + endNum);
}
for(startNum; startNum < endNum; startNum++) {
var instance:String = "cont" + index;
var imageURL:String = "http://www.gessnerengineering.com/system/avatars/" + xmlData.profile[startNum]["id"] + "/thumb/" + xmlData.profile[startNum]["avatar-file-name"];
loadImage(imageURL, instance);
Gessner(root).pages.whoweare_bkg[instance].title.text = xmlData.profile[startNum]["user-id"];
Gessner(root).pages.whoweare_bkg[instance].description.text = xmlData.profile[startNum]["bio"];
instances.push(instance);
index++;
}
}
//=======================================================================================
private function loadImage(imageURL:String, instance:String):void {
//=======================================================================================
var imageLoader:Loader = new Loader();
var imageRequest = new URLRequest(imageURL);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
imageLoader.load(imageRequest);
function onComplete(e:Event) {
var image:Bitmap = (Bitmap)(e.currentTarget.content);
Gessner(root).pages.whoweare_bkg[instance].thumb.addChild(image);
images.push(Gessner(root).pages.whoweare_bkg[instance].thumb.getChildByName(image.name));
imageInstances.push(instance);
//imageLoader.unload();
}
}
//=======================================================================================
private function removeAll():void {
//=======================================================================================
var lengthOfIndex:uint = instances.length;
/*for each(var button:DisplayObject in paginationButtons) {
Gessner(root).pages.whoweare_bkg.pagination.removeChild(button);
}*/
for (var i:uint = 0; i < lengthOfIndex; i++) {
Gessner(root).pages.whoweare_bkg[instances[i]]["title"].text = "";
Gessner(root).pages.whoweare_bkg[instances[i]]["description"].text = "";
try {
Gessner(root).pages.whoweare_bkg[imageInstances[i]].thumb.removeChild(images[i]);
} catch (ArgumentError) {
//trace("error: " + images[i].name + "::" + instances[i]);
}
}
paginationButtons.splice(0, paginationButtons.length);
images.splice(0, lengthOfIndex);
imageInstances.splice(0, lengthOfIndex);
instances.splice(0, lengthOfIndex);
}
}
文档的时间轴操作
this.pages.whoweare_bkg.recent_projects.addEventListener(MouseEvent.CLICK, initXML);
this.pages.whoweare_bkg.our_staff.addEventListener(MouseEvent.CLICK, initXML);
this.whoweare.addEventListener(MouseEvent.CLICK, initXML);
输出 Pastie
##first click
makePagination() target: whoweare
onCompleteXML() target: whoweare
loadProjectXML() got called from onCompleteXML();
projectENDNUM3
##second click
makePagination() target: whoweare
onCompleteXML() target: whoweare
loadProjectXML() got called from onCompleteXML();
projectENDNUM3
makePagination() target: recent_projects
onCompleteXML() target: recent_projects
loadProjectXML() got called from onCompleteXML();
projectENDNUM3
##third click
makePagination() target: whoweare
onCompleteXML() target: whoweare
loadProjectXML() got called from onCompleteXML();
projectENDNUM3
makePagination() target: recent_projects
onCompleteXML() target: recent_projects
loadProjectXML() got called from onCompleteXML();
projectENDNUM3
makePagination() target: recent_projects
onCompleteXML() target: recent_projects
loadProjectXML() got called from onCompleteXML();
projectENDNUM3
##fourth click
makePagination() target: whoweare
onCompleteXML() target: whoweare
loadProjectXML() got called from onCompleteXML();
projectENDNUM3
makePagination() target: recent_projects
onCompleteXML() target: recent_projects
loadProjectXML() got called from onCompleteXML();
projectENDNUM3
makePagination() target: recent_projects
onCompleteXML() target: recent_projects
loadProjectXML() got called from onCompleteXML();
projectENDNUM3
makePagination() target: recent_projects
onCompleteXML() target: recent_projects
loadProjectXML() got called from onCompleteXML();
projectENDNUM3
and so on and so on
答案 0 :(得分:2)
哦,我明白了。它就在这一部分:
xmlLoader.addEventListener(Event.COMPLETE, onCompleteXML);
xmlLoader.load(new URLRequest("http://www.gessnerengineering.com/projects"));
每次调用此代码时,都会向xmlLoader添加一个NEW事件侦听器。因此,每次调用它时,它都会调用onCompleteXML +1次。
答案 1 :(得分:1)
看起来你并没有删除事件监听器 - 如果你想这样做的话。另外,你的目标变量是什么?我没有看到它声明的位置,你的意思是使用e.currentTarget还是什么?
答案 2 :(得分:1)
检查您在时间轴上的操作,并确保在某处有stop()
命令,并避免再次添加事件侦听器。
每当您在时间轴上输入关键帧时,都会添加您的事件侦听器。所以我猜你要去一个不同的框架,然后回到添加事件监听器的同一个框架。