装载机按钮模式
我编写了一些图像滑块代码,可以从 xml 加载图像。一切都很顺利,但是当我想要加载图像按钮模式时,它会出错并显示:
“ReferenceError:错误#1056:无法在 flash.display.Loader 上创建属性buttonMode。”
这是完整的代码:
import flash.display.Stage;
import flash.events.Event;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.xml.XMLDocument;
import flash.text.TextField;
//tween - start
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.events.MouseEvent;
//tween - end
//timer-start
import flash.utils.Timer;
//timer-end
var myStage:Stage = this.stage;
myStage.scaleMode = StageScaleMode.NO_SCALE;
myStage.align = StageAlign.TOP_LEFT;
var sliderXML:XML = new XML();
var sliderXMLurl:String = 'sliderXML.xml';
var sliderXMLreq:URLRequest = new URLRequest(sliderXMLurl);
var sliderXMLloader:URLLoader = new URLLoader(sliderXMLreq);
sliderXMLloader.addEventListener("complete",loadXML);
var sliderNum:int = 0;
var sliderMaxNum:int = 0;
var LastSliderNum:int = 0;
var strTitle:Array = [];
var strPosterLink:Array = [];
var strVideoLink:Array = [];
var poster:Array = [];
var Playing:int = 1;
addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
myStage.addEventListener(Event.RESIZE, ResizeHandler);
var myTimer:Timer = new Timer(10000); //10 second
myTimer.addEventListener(TimerEvent.TIMER, viewNext);
myTimer.start();
function fl_EnterFrameHandler(event:Event):void
{
var swfWidth:int = myStage.stageWidth;
var swfHeight:int = myStage.stageHeight;
slider_bg.width = swfWidth;
slider_bg.height = swfHeight;
}
function loadXML(event:Event):void{
sliderXML=XML(sliderXMLloader.data);
var xmlDoc:XMLDocument = new XMLDocument();
xmlDoc.ignoreWhite = true;
var menuXML:XML = XML(sliderXMLloader.data);
xmlDoc.parseXML(menuXML.toXMLString());
//var X:int = 100;
for each(var listItem:XML in sliderXML..listItem){
strTitle[sliderMaxNum] = listItem.itemTitle.toString();
strPosterLink[sliderMaxNum] = listItem.posterLink.toString();
strVideoLink[sliderMaxNum] = listItem.videoLink.toString();
var _temp:Loader = new Loader();
poster.splice(sliderMaxNum, 0, _temp);
poster[sliderMaxNum].load(new URLRequest(strPosterLink[sliderMaxNum]));
//i think that here must be done something
addChild(poster[sliderMaxNum]);
poster[sliderMaxNum].x = myStage.stageWidth;
poster[sliderMaxNum].y = 28;
poster[sliderMaxNum].buttonMode = true;
poster[sliderMaxNum].addEventListener(MouseEvent.CLICK, poster_click(sliderMaxNum));
sliderMaxNum = sliderMaxNum+1;
}
LastSliderNum = sliderMaxNum - 1;
//*************************************************
var myTween:Tween = new Tween(poster[sliderNum],'x',Strong.easeOut,poster[sliderNum].x,(myStage.stageWidth - 640)/2,2,true);
//*************************************************
}
我认为这是一个问题:
for each(var listItem:XML in sliderXML..listItem){
strTitle[sliderMaxNum] = listItem.itemTitle.toString();
strPosterLink[sliderMaxNum] = listItem.posterLink.toString();
strVideoLink[sliderMaxNum] = listItem.videoLink.toString();
var _temp:Loader = new Loader();
poster.splice(sliderMaxNum, 0, _temp);
poster[sliderMaxNum].load(new URLRequest(strPosterLink[sliderMaxNum]));
//i think that here must be done something
addChild(poster[sliderMaxNum]);
poster[sliderMaxNum].x = myStage.stageWidth;
poster[sliderMaxNum].y = 28;
poster[sliderMaxNum].buttonMode = true;
poster[sliderMaxNum].addEventListener(MouseEvent.CLICK, poster_click(sliderMaxNum));
sliderMaxNum = sliderMaxNum+1;
}
i wrote some piece of code of image slider where i can load images from xml. everything goes fine but when i want to make loaded image button mode it goes wrong and seys:
"ReferenceError: Error #1056: Cannot create property buttonMode on flash.display.Loader."
here is a full code:
import flash.display.Stage;
import flash.events.Event;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.xml.XMLDocument;
import flash.text.TextField;
//tween - start
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.events.MouseEvent;
//tween - end
//timer-start
import flash.utils.Timer;
//timer-end
var myStage:Stage = this.stage;
myStage.scaleMode = StageScaleMode.NO_SCALE;
myStage.align = StageAlign.TOP_LEFT;
var sliderXML:XML = new XML();
var sliderXMLurl:String = 'sliderXML.xml';
var sliderXMLreq:URLRequest = new URLRequest(sliderXMLurl);
var sliderXMLloader:URLLoader = new URLLoader(sliderXMLreq);
sliderXMLloader.addEventListener("complete",loadXML);
var sliderNum:int = 0;
var sliderMaxNum:int = 0;
var LastSliderNum:int = 0;
var strTitle:Array = [];
var strPosterLink:Array = [];
var strVideoLink:Array = [];
var poster:Array = [];
var Playing:int = 1;
addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
myStage.addEventListener(Event.RESIZE, ResizeHandler);
var myTimer:Timer = new Timer(10000); //10 second
myTimer.addEventListener(TimerEvent.TIMER, viewNext);
myTimer.start();
function fl_EnterFrameHandler(event:Event):void
{
var swfWidth:int = myStage.stageWidth;
var swfHeight:int = myStage.stageHeight;
slider_bg.width = swfWidth;
slider_bg.height = swfHeight;
}
function loadXML(event:Event):void{
sliderXML=XML(sliderXMLloader.data);
var xmlDoc:XMLDocument = new XMLDocument();
xmlDoc.ignoreWhite = true;
var menuXML:XML = XML(sliderXMLloader.data);
xmlDoc.parseXML(menuXML.toXMLString());
//var X:int = 100;
for each(var listItem:XML in sliderXML..listItem){
strTitle[sliderMaxNum] = listItem.itemTitle.toString();
strPosterLink[sliderMaxNum] = listItem.posterLink.toString();
strVideoLink[sliderMaxNum] = listItem.videoLink.toString();
var _temp:Loader = new Loader();
poster.splice(sliderMaxNum, 0, _temp);
poster[sliderMaxNum].load(new URLRequest(strPosterLink[sliderMaxNum]));
//i think that here must be done something
addChild(poster[sliderMaxNum]);
poster[sliderMaxNum].x = myStage.stageWidth;
poster[sliderMaxNum].y = 28;
poster[sliderMaxNum].buttonMode = true;
poster[sliderMaxNum].addEventListener(MouseEvent.CLICK, poster_click(sliderMaxNum));
sliderMaxNum = sliderMaxNum+1;
}
LastSliderNum = sliderMaxNum - 1;
//*************************************************
var myTween:Tween = new Tween(poster[sliderNum],'x',Strong.easeOut,poster[sliderNum].x,(myStage.stageWidth - 640)/2,2,true);
//*************************************************
}
i think that here is a problem:
for each(var listItem:XML in sliderXML..listItem){
strTitle[sliderMaxNum] = listItem.itemTitle.toString();
strPosterLink[sliderMaxNum] = listItem.posterLink.toString();
strVideoLink[sliderMaxNum] = listItem.videoLink.toString();
var _temp:Loader = new Loader();
poster.splice(sliderMaxNum, 0, _temp);
poster[sliderMaxNum].load(new URLRequest(strPosterLink[sliderMaxNum]));
//i think that here must be done something
addChild(poster[sliderMaxNum]);
poster[sliderMaxNum].x = myStage.stageWidth;
poster[sliderMaxNum].y = 28;
poster[sliderMaxNum].buttonMode = true;
poster[sliderMaxNum].addEventListener(MouseEvent.CLICK, poster_click(sliderMaxNum));
sliderMaxNum = sliderMaxNum+1;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
简短的回答:海报数组中的对象是 Loader,而不是 Sprite。 ButtonMode 实际上是 Sprite 类的一个属性。 Loader 与 Sprite 相关,因为它们都源自 DisplayObject,但 loader 有一些自己独特的属性,并且或多或少生活在自己的家族树分支中。
你可以做这样的事情。找到显示“poster[sliderMaxNum].buttonMode = true”的行,并将其更改为如下所示:
这应该为您提供您想要的行为。它并不完全漂亮,也不是类型安全的(这意味着如果您向海报添加除加载程序之外的任何内容,它就会损坏) - 但出于您的目的,它应该可以工作。
让我知道这是否解决了问题,或者其中的任何部分是否令人困惑。
干杯!
Short answer: The object that you have in your poster array is a Loader, not a Sprite. buttonMode is actually a property of the Sprite class. Loader is related to Sprite in that both of them descend from DisplayObject, but loader has some unique properties of its own and more or less lives in its own branch of the family tree.
You could do something like this. Find the line that says "poster[sliderMaxNum].buttonMode = true" and change it to say something like this:
That SHOULD give you the behavior you want. It's not entirely pretty and it's not type-safe (meaning if you add anything other than a Loader to poster, it will break) - but for your purposes it should work.
Let me know if that solves the problem, or if any part of that is confusing.
Cheers!
您可以将 Loader 包装在它们自己的 Sprite 中:
You can wrap the Loaders inside their own Sprites:
我已经找到了解决方案并做了一些更改,所以现在我的代码如下所示:
所以这里一切正常。非常感谢大家!!!!!!!!!
i have found the solution and did some changes so now my code looks like this:
so everythig works fine here. and great thanks all of you!!!!!!!!!
你有没有尝试过这个:
Have you tried this: