装载机按钮模式

发布于 2024-10-27 01:04:43 字数 4287 浏览 7 评论 0原文

我编写了一些图像滑块代码,可以从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

枯叶蝶 2024-11-03 01:04:43

简短的回答:海报数组中的对象是 Loader,而不是 Sprite。 ButtonMode 实际上是 Sprite 类的一个属性。 Loader 与 Sprite 相关,因为它们都源自 DisplayObject,但 loader 有一些自己独特的属性,并且或多或少生活在自己的家族树分支中。

你可以做这样的事情。找到显示“poster[sliderMaxNum].buttonMode = true”的行,并将其更改为如下所示:

Sprite(poster[sliderMaxNum].content).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:

Sprite(poster[sliderMaxNum].content).buttonMode = true;

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!

书信已泛黄 2024-11-03 01:04:43

您可以将 Loader 包装在它们自己的 Sprite 中:

             var _temp:Loader = new Loader();
             poster.splice(sliderMaxNum, 0, new Sprite());
             poster[sliderMaxNum].addChild(_temp);
             _temp.load(new URLRequest(strPosterLink[sliderMaxNum]));
             addChild(poster[sliderMaxNum]);
             poster[sliderMaxNum].x = myStage.stageWidth;
             poster[sliderMaxNum].y = 28;
             poster[sliderMaxNum].buttonMode = true;

You can wrap the Loaders inside their own Sprites:

             var _temp:Loader = new Loader();
             poster.splice(sliderMaxNum, 0, new Sprite());
             poster[sliderMaxNum].addChild(_temp);
             _temp.load(new URLRequest(strPosterLink[sliderMaxNum]));
             addChild(poster[sliderMaxNum]);
             poster[sliderMaxNum].x = myStage.stageWidth;
             poster[sliderMaxNum].y = 28;
             poster[sliderMaxNum].buttonMode = true;
柏林苍穹下 2024-11-03 01:04:43

我已经找到了解决方案并做了一些更改,所以现在我的代码如下所示:

             var _temp:Loader = new Loader();
             poster.splice(sliderMaxNum, 0, _temp);
             poster[sliderMaxNum].load(new URLRequest(strPosterLink[sliderMaxNum]));
         poster[sliderMaxNum].contentLoaderInfo.addEventListener(Event.COMPLETE, loadedImage);


function loadedImage(event:Event):void {
   posterWidth[sliderMaxNum] = event.target.content.width;
   posterHeight[sliderMaxNum] = event.target.content.height;
   var PosterSprite:Sprite    = new Sprite();
   PosterSprite.addChild(poster[sliderMaxNum]);
   PosterSprite.buttonMode    = true;
   PosterSprite.useHandCursor = true;
   addChild(PosterSprite);
   poster[sliderMaxNum].x = myStage.stageWidth;
   poster[sliderMaxNum].y = 28;

   poster[sliderMaxNum].addEventListener(MouseEvent.CLICK, poster_click(sliderMaxNum));

   sliderMaxNum = sliderMaxNum+1;
}

所以这里一切正常。非常感谢大家!!!!!!!!!

i have found the solution and did some changes so now my code looks like this:

             var _temp:Loader = new Loader();
             poster.splice(sliderMaxNum, 0, _temp);
             poster[sliderMaxNum].load(new URLRequest(strPosterLink[sliderMaxNum]));
         poster[sliderMaxNum].contentLoaderInfo.addEventListener(Event.COMPLETE, loadedImage);


function loadedImage(event:Event):void {
   posterWidth[sliderMaxNum] = event.target.content.width;
   posterHeight[sliderMaxNum] = event.target.content.height;
   var PosterSprite:Sprite    = new Sprite();
   PosterSprite.addChild(poster[sliderMaxNum]);
   PosterSprite.buttonMode    = true;
   PosterSprite.useHandCursor = true;
   addChild(PosterSprite);
   poster[sliderMaxNum].x = myStage.stageWidth;
   poster[sliderMaxNum].y = 28;

   poster[sliderMaxNum].addEventListener(MouseEvent.CLICK, poster_click(sliderMaxNum));

   sliderMaxNum = sliderMaxNum+1;
}

so everythig works fine here. and great thanks all of you!!!!!!!!!

只是在用心讲痛 2024-11-03 01:04:43

你有没有尝试过这个:

poster[sliderMaxNum].contentLoaderInfo.content.buttonMode = true;

Have you tried this:

poster[sliderMaxNum].contentLoaderInfo.content.buttonMode = true;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文