ActionScript 3.0 预加载器问题

发布于 2024-07-12 07:49:36 字数 18002 浏览 8 评论 0 原文

首先,我非常感谢任何帮助,一如既往......

我已经从 Jarrod 的高级 AS3 预加载器教程。 我在其他地方进行了搜索,这似乎是我的最佳选择,因为这是我了解的唯一不需要 2 个 SWF 文件的选择。

我的代码实际上分为两个类,我的预加载器类和我的程序类。 我的问题是预加载器仅加载闪存中的图形,而不实际启动程序类。 我的问题是如何预加载以启动程序类?这两个文件的完整代码如下。

Preloader.as

package {
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;
    import fl.containers.ScrollPane;
    import flash.filters.*;

    public class Preloader extends MovieClip {
        public static  const ENTRY_FRAME:Number=3;
        public static  const DOCUMENT_CLASS:String='Program';
        public var myText:TextField;
        public var myFormat:TextFormat;
        private var progressBar:Sprite;
        private var progressText:TextField;
        public function Preloader() {

            stop();
            progressBar = getChildByName("loadbar_mc") as Sprite;
            progressText = getChildByName("loading_txt") as TextField;

            progressBar.scaleX = 0;

            myFormat = new TextFormat();
            myFormat.font="Helvetica";
            myFormat.color = 0x000000;
            myFormat.size = 24;



            loaderInfo.addEventListener(Event.INIT, initHandler);
            loaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            loaderInfo.addEventListener(Event.COMPLETE, completeHandler);
            loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
        }
        private function initHandler(event:Event):void {
            progressBar.scaleX = 0;
            progressText.text = "Loading 0%";

        }
        private function progressHandler(event:ProgressEvent):void {
            var loaded:uint = event.bytesLoaded;
            var total:uint = event.bytesTotal;

            var percentLoaded:Number = Math.round((loaded/total) * 50);
            progressBar.scaleX = loaded/total;
            progressText.text = "Loading " + percentLoaded + "%";

        }
        private function completeHandler(event:Event):void {
            play();
            addEventListener(Event.ENTER_FRAME, enterFrameHandler);

        }
        private function enterFrameHandler(event:Event):void {
            if (currentFrame >= Preloader.ENTRY_FRAME) {
                removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
                stop();
                main();

            }


        }
        private function errorHandler(event:IOErrorEvent):void {
            myText.text = ("Sorry, there was an error. " + event);
            myText.setTextFormat(myFormat);


        }
        private function main():void {

            var programClass:Class = loaderInfo.applicationDomain.getDefinition(Preloader.DOCUMENT_CLASS) as Class;
            var program:Sprite = new programClass() as Sprite;

            addChild(program);


        }

    }
}

Program.as

package {
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.text.*;
    import fl.controls.TextInput;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import fl.containers.ScrollPane;
    import flash.geom.Rectangle;
    import fl.controls.Label;



    public class Program extends Sprite {
        public function Program() {
            //define variable
            var startX:Number;
            var startY:Number;
            var counter:Number = 0;
            var intMessages:Number = 550;
            var limit:Number = 10;
            var intBoardSize:Number = 476*(Math.round(intMessages/15)+1);
            var intMessageMinX:Number = 35;
            var intMessageMaxX:Number = intBoardSize-99;
            var intMessageMinY:Number = 50;
            var intMessageMaxY:Number = 310;
            var activeGloveName:String = ""
            var intDegreeHigh:Number = 45;
            var intDegreeLow:Number = -45;
            var newGlove:mcGlove;

            //create objects
            var myGlove:mcGlove = new mcGlove();
            var showGlove:mcGlove = new mcGlove
            var mcglovetarget:mcGloveTarget = new mcGloveTarget();
            var myDropShadowFilterSmall = new DropShadowFilter (2,45,0x000000,0.65,3,3,2,3,false,false,false);
            var myDropShadowFilterDown = new DropShadowFilter (3,45,0x000000,0.65,5,5,2,3,false,false,false);
            var myDropShadowFilterUp = new DropShadowFilter (5,45,0x000000,0.65,7,7,2,3,false,false,false);
            var topShadow = new DropShadowFilter (3,90,0x000000,0.35,8,8,2,3,false,false,false);
            var pinkline:Sprite = new Sprite();
            var searchBox:Sprite = new Sprite();
            var txtSearchBox:TextInput = new TextInput();
            var sSearchBox_Label:String = "Go to glove #";
            var messageFormat:TextFormat = new TextFormat();
            var messageTextField:Label = new Label();
            var searchBoxLFormat:TextFormat = new TextFormat();
            var txtSearchBox_Label:TextField = new TextField();
            var SearchBoxBg:Sprite = new Sprite();
            var topShadowBox:Sprite = new Sprite();
            var searchButton:searchBtn = new searchBtn();
            var alertRect:Rectangle = new Rectangle(0,0,848,393);
            var errorMessage:AlertBox = new AlertBox(alertRect);
            var holder:MovieClip = new MovieClip();
            var aMessages:Array = new Array();

            //Create a glove for each message
            for (var gloveCount = 0; gloveCount < intMessages; gloveCount++){
                aMessages[gloveCount] = new mcGlove();
                aMessages[gloveCount] = createMessage(aMessages[gloveCount], gloveCount, gloveCount);
            }


            var scrollPane:ScrollPane = new ScrollPane();
            scrollPane.verticalScrollPolicy = "false";
            scrollPane.move(374, 0);
            scrollPane.setSize(476, 370);
            scrollPane.horizontalLineScrollSize = 120;

            topShadowBox.graphics.beginFill(0x333333);
            topShadowBox.graphics.drawRect(0,0,870,5);
            topShadowBox.x = -10;
            topShadowBox.y = -5;
            topShadowBox.filters = [topShadow];

            pinkline.graphics.beginFill(0xDB9195);
            pinkline.graphics.drawRect(0,0,476,2);
            pinkline.x = 374;
            pinkline.y = 353;

            searchBox.graphics.beginFill(0xDB9195);
            searchBox.graphics.drawRect(0,0,476,25);
            searchBox.x = 374;
            searchBox.y = 370;

            SearchBoxBg.graphics.beginFill(0xffffff);
            SearchBoxBg.graphics.drawRect(0,0,35,17);
            SearchBoxBg.x = 475;
            SearchBoxBg.y = 374;

            txtSearchBox.width = 35;
            txtSearchBox.height = 15;
            txtSearchBox.move(475,375);
            txtSearchBox.restrict = "0-9";
            txtSearchBox.maxChars = 4;
            //txtSearchBox.background = "0xffffff";
            //txtSearchBox.border = "0x0xDB9195";

            searchBoxLFormat.font="Helvetica";
            searchBoxLFormat.color = 0xffffff;
            searchBoxLFormat.bold = true;
            searchBoxLFormat.size = 10;

            txtSearchBox_Label.x = 400;
            txtSearchBox_Label.y = 374;
            txtSearchBox_Label.width = 70;
            txtSearchBox_Label.height = 17;
            txtSearchBox_Label.text = sSearchBox_Label;
            txtSearchBox_Label.setTextFormat(searchBoxLFormat);

            searchButton.x = 534;
            searchButton.y = 382;

            //add to frame
            sortObjects();

            scrollPane.source = holder;         

            //create instance names for referancing/compairing objects
            myGlove.name = "mcglove";
            myGlove.setGloveMessage("My Sister Suzy, I pray that she will be ok. I love here so much, she is the best sister ever.  I miss you RIP");
            mcglovetarget.name = "mcglovetarget";

            messageFormat.font="Helvetica";
            messageFormat.color = 0xffffff;
            messageFormat.bold = true;
            messageFormat.size = 17;
            messageFormat.align = "center";

            messageTextField.x = -85;
            messageTextField.y = -40;
            messageTextField.width = 135;
            messageTextField.height = 140;
            messageTextField.text = myGlove.getGloveMessage();
            messageTextField.wordWrap = true;
            messageTextField.mouseEnabled = false;
            messageTextField.buttonMode = true;
            messageTextField.setStyle("textFormat", messageFormat);
            //messageTextField.hitArea = 0;
            myGlove.addChild(messageTextField);         

            //position the glove and modify apperiance
            myGlove.x = 163;
            myGlove.y = 211;
            myGlove.filters = [myDropShadowFilterDown];
            //myGlove.addChild(messageTextField);
            showGlove.x = 163;
            showGlove.y = 211;
            showGlove.filters = [myDropShadowFilterDown];
            mcglovetarget.x = 615;
            mcglovetarget.y = 211;
            mcglovetarget.alpha = 0

            //action listeners
            myGlove.addEventListener(MouseEvent.MOUSE_DOWN, selectGlove);
            myGlove.addEventListener(MouseEvent.MOUSE_UP, releaseGlove);
            searchButton.addEventListener(MouseEvent.CLICK, searchMessages);
            txtSearchBox.addEventListener(KeyboardEvent.KEY_UP, checkForEnter);


            function selectGlove(event:MouseEvent):void {
                event.currentTarget.startDrag(true);
                var myTargetName:String = event.currentTarget.name + "target";
                var myTarget:DisplayObject = getChildByName(myTargetName);
                myGlove.filters = [myDropShadowFilterUp];
                addChild(myTarget);
                event.currentTarget.parent.addChild(event.currentTarget);
                addChild(topShadowBox);
                myTarget.alpha = .5;
                startX = event.currentTarget.x;
                startY = event.currentTarget.y;
            }

            function releaseGlove(event:MouseEvent):void {
                event.currentTarget.stopDrag();
                var myTargetName:String = event.currentTarget.name + "target";
                var myTarget:DisplayObject = getChildByName(myTargetName);
                event.currentTarget.filters = [myDropShadowFilterDown];
                myTarget.alpha = 0;

                if (event.currentTarget.dropTarget != null && event.currentTarget.dropTarget.parent == myTarget){
                    event.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN, selectGlove);
                    event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, releaseGlove);
                    event.currentTarget.x = myTarget.x;
                    event.currentTarget.y = myTarget.y;
                    var myTween:Tween = new Tween(getChildByName(event.currentTarget.name), "scaleX",Strong.easeOut,getChildByName(event.currentTarget.name).scaleX,.28,2,true);
                    var myTween2:Tween = new Tween(getChildByName(event.currentTarget.name), "scaleY",Strong.easeOut,getChildByName(event.currentTarget.name).scaleY,.28,2,true);
                    holder.addChild(getChildByName(event.currentTarget.name));
                    event.currentTarget.removeChild(messageTextField);
                    scrollPane.source = holder;
                    holder.getChildByName(event.currentTarget.name).x=Math.round(Math.random() * (470+Math.round(scrollPane.horizontalScrollPosition) - Math.round(scrollPane.horizontalScrollPosition))) + Math.round(scrollPane.horizontalScrollPosition);
                    holder.getChildByName(event.currentTarget.name).y=Math.round(Math.random() * (intMessageMaxY - intMessageMinY)) + intMessageMinY;
                    holder.getChildByName(event.currentTarget.name).addEventListener(MouseEvent.MOUSE_DOWN, clickMessage);
                    holder.getChildByName(event.currentTarget.name).addEventListener(MouseEvent.MOUSE_UP, releaseMessage);
                    event.currentTarget.name = "" + intMessages;
                    addChild(showGlove);
                    messageTextField.text = "Select a glove to view its message here.";
                    showGlove.addChild(messageTextField);
                } else {
                    event.currentTarget.x = startX;
                    event.currentTarget.y = startY;
                }

                //sortObjects();
                addChild(mcglovetarget);
                addChild(scrollPane);
                addChild(pinkline);
                addChild(searchBox);
                addChild(SearchBoxBg);
                addChild(txtSearchBox);
                addChild(txtSearchBox_Label);
                addChild(searchButton);
                addChild(topShadowBox);
            }

            function position(target) {
                target.x = Math.round(Math.random() * (intMessageMaxX - intMessageMinX)) + intMessageMinX;
                target.y = Math.round(Math.random() * (intMessageMaxY - intMessageMinY)) + intMessageMinY;
                for (var i:uint=0; i<aMessages.length -1 ; i++) {
                    if(target.hitTestObject(aMessages[i]) && counter < limit){
                        counter++;
                        position(target);
                        //return false;
                    };
                }
            } 

            function createMessage(newGlove:mcGlove, sName:String, sMessage:String){
                newGlove.scaleX = .28;
                newGlove.scaleY = .28;
                counter = 0;
                position(newGlove);
                newGlove.rotation = (0, 0, 0, Math.round(Math.random() * (intDegreeHigh - intDegreeLow)) + intDegreeLow);
                newGlove.filters = [myDropShadowFilterSmall];
                newGlove.name = sName;
                holder.addChild(newGlove);
                newGlove.setGloveMessage(sMessage);
                newGlove.addEventListener(MouseEvent.MOUSE_DOWN, clickMessage);
                newGlove.addEventListener(MouseEvent.MOUSE_UP, releaseMessage);
                newGlove.buttonMode = true;
                return newGlove;
            }

            function clickMessage(event:MouseEvent):void{
                selectMessage(event.target);
            }

            function checkForEnter(event:KeyboardEvent):void
            {
                if (event.keyCode == 13) // If Keypress is Enter
                {
                    searchMessages();
                }
            }


            function searchMessages():void{
                if (showGlove.parent == mcglovetarget.parent){
                    if ( txtSearchBox.text != "" ){
                        var searchTarget:DisplayObject = holder.getChildByName(txtSearchBox.text);
                        if (searchTarget){
                            selectMessage(searchTarget);
                            scrollPane.horizontalScrollPosition = searchTarget.x - 220;
                        }else if(1==1){ //if in file
                            gloveCount = aMessages.length;
                            aMessages[gloveCount] = new mcGlove();
                            aMessages[gloveCount] = createMessage(aMessages[gloveCount], txtSearchBox.text, txtSearchBox.text);
                            selectMessage(aMessages[gloveCount]);
                            scrollPane.horizontalScrollPosition = aMessages[gloveCount].x - 220;
                        }else{
                            errorMessage.setAlertText("Sorry, the glove you are searching for does not exist.");
                            addChild(errorMessage);
                        }
                    }
                }else{
                    errorMessage.setAlertText("You must post your message first, otherwise your message will be lost.");
                    addChild(errorMessage);
                }
            }

            function selectMessage(object:mcGlove):void{
                if (showGlove.parent == mcglovetarget.parent){
                    if (activeGloveName != ""){
                        var activeGlove:DisplayObject = holder.getChildByName(activeGloveName);
                        activeGlove.filters = [myDropShadowFilterSmall];
                        activeGlove.scaleX = .28;
                        activeGlove.scaleY = .28;
                        holder.addChild(activeGlove);
                    }
                    activeGloveName = object.name;
                    //event.target.dragIt();
                    holder.addChild(object);
                    object.filters = [new GlowFilter(0xABEEFC, .65, 15, 15, 1, 1, false, false)];
                    object.scaleX = .35;
                    object.scaleY = .35;
                    messageTextField.text = object.getGloveMessage();
                }else{
                    errorMessage.setAlertText("You must post your message first, otherwise your message will be lost.");
                    addChild(errorMessage);
                }
            }

            function releaseMessage(event:MouseEvent):void{
                event.target.dropIt();
            }



            function sortObjects():void{
                addChild(mcglovetarget);
                addChild(scrollPane);
                addChild(pinkline);
                addChild(searchBox);
                addChild(SearchBoxBg);
                addChild(txtSearchBox);
                addChild(txtSearchBox_Label);
                addChild(searchButton);
                addChild(myGlove);
                addChild(topShadowBox);
            }

            myGlove.buttonMode = true;
            searchButton.buttonMode = true;

        }
    }
}

First off, I greatly appreciate any help, as always....

I have created a preloader from Jarrod's Advanced AS3 Preloader Tutorail. I searched elsewhere and this seemed like my best option as it was the only one I understood that did not require 2 SWF files.

My code is really in 2 classes, my preloader class and my program class. My problem is that the preloader is only loading the graphics that are in my flash and not actually initiating the program class. My question is how do I get my preloading to initiate the program class? The full code for both files are below.

Preloader.as

package {
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;
    import fl.containers.ScrollPane;
    import flash.filters.*;

    public class Preloader extends MovieClip {
        public static  const ENTRY_FRAME:Number=3;
        public static  const DOCUMENT_CLASS:String='Program';
        public var myText:TextField;
        public var myFormat:TextFormat;
        private var progressBar:Sprite;
        private var progressText:TextField;
        public function Preloader() {

            stop();
            progressBar = getChildByName("loadbar_mc") as Sprite;
            progressText = getChildByName("loading_txt") as TextField;

            progressBar.scaleX = 0;

            myFormat = new TextFormat();
            myFormat.font="Helvetica";
            myFormat.color = 0x000000;
            myFormat.size = 24;



            loaderInfo.addEventListener(Event.INIT, initHandler);
            loaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            loaderInfo.addEventListener(Event.COMPLETE, completeHandler);
            loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
        }
        private function initHandler(event:Event):void {
            progressBar.scaleX = 0;
            progressText.text = "Loading 0%";

        }
        private function progressHandler(event:ProgressEvent):void {
            var loaded:uint = event.bytesLoaded;
            var total:uint = event.bytesTotal;

            var percentLoaded:Number = Math.round((loaded/total) * 50);
            progressBar.scaleX = loaded/total;
            progressText.text = "Loading " + percentLoaded + "%";

        }
        private function completeHandler(event:Event):void {
            play();
            addEventListener(Event.ENTER_FRAME, enterFrameHandler);

        }
        private function enterFrameHandler(event:Event):void {
            if (currentFrame >= Preloader.ENTRY_FRAME) {
                removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
                stop();
                main();

            }


        }
        private function errorHandler(event:IOErrorEvent):void {
            myText.text = ("Sorry, there was an error. " + event);
            myText.setTextFormat(myFormat);


        }
        private function main():void {

            var programClass:Class = loaderInfo.applicationDomain.getDefinition(Preloader.DOCUMENT_CLASS) as Class;
            var program:Sprite = new programClass() as Sprite;

            addChild(program);


        }

    }
}

Program.as

package {
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.text.*;
    import fl.controls.TextInput;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import fl.containers.ScrollPane;
    import flash.geom.Rectangle;
    import fl.controls.Label;



    public class Program extends Sprite {
        public function Program() {
            //define variable
            var startX:Number;
            var startY:Number;
            var counter:Number = 0;
            var intMessages:Number = 550;
            var limit:Number = 10;
            var intBoardSize:Number = 476*(Math.round(intMessages/15)+1);
            var intMessageMinX:Number = 35;
            var intMessageMaxX:Number = intBoardSize-99;
            var intMessageMinY:Number = 50;
            var intMessageMaxY:Number = 310;
            var activeGloveName:String = ""
            var intDegreeHigh:Number = 45;
            var intDegreeLow:Number = -45;
            var newGlove:mcGlove;

            //create objects
            var myGlove:mcGlove = new mcGlove();
            var showGlove:mcGlove = new mcGlove
            var mcglovetarget:mcGloveTarget = new mcGloveTarget();
            var myDropShadowFilterSmall = new DropShadowFilter (2,45,0x000000,0.65,3,3,2,3,false,false,false);
            var myDropShadowFilterDown = new DropShadowFilter (3,45,0x000000,0.65,5,5,2,3,false,false,false);
            var myDropShadowFilterUp = new DropShadowFilter (5,45,0x000000,0.65,7,7,2,3,false,false,false);
            var topShadow = new DropShadowFilter (3,90,0x000000,0.35,8,8,2,3,false,false,false);
            var pinkline:Sprite = new Sprite();
            var searchBox:Sprite = new Sprite();
            var txtSearchBox:TextInput = new TextInput();
            var sSearchBox_Label:String = "Go to glove #";
            var messageFormat:TextFormat = new TextFormat();
            var messageTextField:Label = new Label();
            var searchBoxLFormat:TextFormat = new TextFormat();
            var txtSearchBox_Label:TextField = new TextField();
            var SearchBoxBg:Sprite = new Sprite();
            var topShadowBox:Sprite = new Sprite();
            var searchButton:searchBtn = new searchBtn();
            var alertRect:Rectangle = new Rectangle(0,0,848,393);
            var errorMessage:AlertBox = new AlertBox(alertRect);
            var holder:MovieClip = new MovieClip();
            var aMessages:Array = new Array();

            //Create a glove for each message
            for (var gloveCount = 0; gloveCount < intMessages; gloveCount++){
                aMessages[gloveCount] = new mcGlove();
                aMessages[gloveCount] = createMessage(aMessages[gloveCount], gloveCount, gloveCount);
            }


            var scrollPane:ScrollPane = new ScrollPane();
            scrollPane.verticalScrollPolicy = "false";
            scrollPane.move(374, 0);
            scrollPane.setSize(476, 370);
            scrollPane.horizontalLineScrollSize = 120;

            topShadowBox.graphics.beginFill(0x333333);
            topShadowBox.graphics.drawRect(0,0,870,5);
            topShadowBox.x = -10;
            topShadowBox.y = -5;
            topShadowBox.filters = [topShadow];

            pinkline.graphics.beginFill(0xDB9195);
            pinkline.graphics.drawRect(0,0,476,2);
            pinkline.x = 374;
            pinkline.y = 353;

            searchBox.graphics.beginFill(0xDB9195);
            searchBox.graphics.drawRect(0,0,476,25);
            searchBox.x = 374;
            searchBox.y = 370;

            SearchBoxBg.graphics.beginFill(0xffffff);
            SearchBoxBg.graphics.drawRect(0,0,35,17);
            SearchBoxBg.x = 475;
            SearchBoxBg.y = 374;

            txtSearchBox.width = 35;
            txtSearchBox.height = 15;
            txtSearchBox.move(475,375);
            txtSearchBox.restrict = "0-9";
            txtSearchBox.maxChars = 4;
            //txtSearchBox.background = "0xffffff";
            //txtSearchBox.border = "0x0xDB9195";

            searchBoxLFormat.font="Helvetica";
            searchBoxLFormat.color = 0xffffff;
            searchBoxLFormat.bold = true;
            searchBoxLFormat.size = 10;

            txtSearchBox_Label.x = 400;
            txtSearchBox_Label.y = 374;
            txtSearchBox_Label.width = 70;
            txtSearchBox_Label.height = 17;
            txtSearchBox_Label.text = sSearchBox_Label;
            txtSearchBox_Label.setTextFormat(searchBoxLFormat);

            searchButton.x = 534;
            searchButton.y = 382;

            //add to frame
            sortObjects();

            scrollPane.source = holder;         

            //create instance names for referancing/compairing objects
            myGlove.name = "mcglove";
            myGlove.setGloveMessage("My Sister Suzy, I pray that she will be ok. I love here so much, she is the best sister ever.  I miss you RIP");
            mcglovetarget.name = "mcglovetarget";

            messageFormat.font="Helvetica";
            messageFormat.color = 0xffffff;
            messageFormat.bold = true;
            messageFormat.size = 17;
            messageFormat.align = "center";

            messageTextField.x = -85;
            messageTextField.y = -40;
            messageTextField.width = 135;
            messageTextField.height = 140;
            messageTextField.text = myGlove.getGloveMessage();
            messageTextField.wordWrap = true;
            messageTextField.mouseEnabled = false;
            messageTextField.buttonMode = true;
            messageTextField.setStyle("textFormat", messageFormat);
            //messageTextField.hitArea = 0;
            myGlove.addChild(messageTextField);         

            //position the glove and modify apperiance
            myGlove.x = 163;
            myGlove.y = 211;
            myGlove.filters = [myDropShadowFilterDown];
            //myGlove.addChild(messageTextField);
            showGlove.x = 163;
            showGlove.y = 211;
            showGlove.filters = [myDropShadowFilterDown];
            mcglovetarget.x = 615;
            mcglovetarget.y = 211;
            mcglovetarget.alpha = 0

            //action listeners
            myGlove.addEventListener(MouseEvent.MOUSE_DOWN, selectGlove);
            myGlove.addEventListener(MouseEvent.MOUSE_UP, releaseGlove);
            searchButton.addEventListener(MouseEvent.CLICK, searchMessages);
            txtSearchBox.addEventListener(KeyboardEvent.KEY_UP, checkForEnter);


            function selectGlove(event:MouseEvent):void {
                event.currentTarget.startDrag(true);
                var myTargetName:String = event.currentTarget.name + "target";
                var myTarget:DisplayObject = getChildByName(myTargetName);
                myGlove.filters = [myDropShadowFilterUp];
                addChild(myTarget);
                event.currentTarget.parent.addChild(event.currentTarget);
                addChild(topShadowBox);
                myTarget.alpha = .5;
                startX = event.currentTarget.x;
                startY = event.currentTarget.y;
            }

            function releaseGlove(event:MouseEvent):void {
                event.currentTarget.stopDrag();
                var myTargetName:String = event.currentTarget.name + "target";
                var myTarget:DisplayObject = getChildByName(myTargetName);
                event.currentTarget.filters = [myDropShadowFilterDown];
                myTarget.alpha = 0;

                if (event.currentTarget.dropTarget != null && event.currentTarget.dropTarget.parent == myTarget){
                    event.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN, selectGlove);
                    event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, releaseGlove);
                    event.currentTarget.x = myTarget.x;
                    event.currentTarget.y = myTarget.y;
                    var myTween:Tween = new Tween(getChildByName(event.currentTarget.name), "scaleX",Strong.easeOut,getChildByName(event.currentTarget.name).scaleX,.28,2,true);
                    var myTween2:Tween = new Tween(getChildByName(event.currentTarget.name), "scaleY",Strong.easeOut,getChildByName(event.currentTarget.name).scaleY,.28,2,true);
                    holder.addChild(getChildByName(event.currentTarget.name));
                    event.currentTarget.removeChild(messageTextField);
                    scrollPane.source = holder;
                    holder.getChildByName(event.currentTarget.name).x=Math.round(Math.random() * (470+Math.round(scrollPane.horizontalScrollPosition) - Math.round(scrollPane.horizontalScrollPosition))) + Math.round(scrollPane.horizontalScrollPosition);
                    holder.getChildByName(event.currentTarget.name).y=Math.round(Math.random() * (intMessageMaxY - intMessageMinY)) + intMessageMinY;
                    holder.getChildByName(event.currentTarget.name).addEventListener(MouseEvent.MOUSE_DOWN, clickMessage);
                    holder.getChildByName(event.currentTarget.name).addEventListener(MouseEvent.MOUSE_UP, releaseMessage);
                    event.currentTarget.name = "" + intMessages;
                    addChild(showGlove);
                    messageTextField.text = "Select a glove to view its message here.";
                    showGlove.addChild(messageTextField);
                } else {
                    event.currentTarget.x = startX;
                    event.currentTarget.y = startY;
                }

                //sortObjects();
                addChild(mcglovetarget);
                addChild(scrollPane);
                addChild(pinkline);
                addChild(searchBox);
                addChild(SearchBoxBg);
                addChild(txtSearchBox);
                addChild(txtSearchBox_Label);
                addChild(searchButton);
                addChild(topShadowBox);
            }

            function position(target) {
                target.x = Math.round(Math.random() * (intMessageMaxX - intMessageMinX)) + intMessageMinX;
                target.y = Math.round(Math.random() * (intMessageMaxY - intMessageMinY)) + intMessageMinY;
                for (var i:uint=0; i<aMessages.length -1 ; i++) {
                    if(target.hitTestObject(aMessages[i]) && counter < limit){
                        counter++;
                        position(target);
                        //return false;
                    };
                }
            } 

            function createMessage(newGlove:mcGlove, sName:String, sMessage:String){
                newGlove.scaleX = .28;
                newGlove.scaleY = .28;
                counter = 0;
                position(newGlove);
                newGlove.rotation = (0, 0, 0, Math.round(Math.random() * (intDegreeHigh - intDegreeLow)) + intDegreeLow);
                newGlove.filters = [myDropShadowFilterSmall];
                newGlove.name = sName;
                holder.addChild(newGlove);
                newGlove.setGloveMessage(sMessage);
                newGlove.addEventListener(MouseEvent.MOUSE_DOWN, clickMessage);
                newGlove.addEventListener(MouseEvent.MOUSE_UP, releaseMessage);
                newGlove.buttonMode = true;
                return newGlove;
            }

            function clickMessage(event:MouseEvent):void{
                selectMessage(event.target);
            }

            function checkForEnter(event:KeyboardEvent):void
            {
                if (event.keyCode == 13) // If Keypress is Enter
                {
                    searchMessages();
                }
            }


            function searchMessages():void{
                if (showGlove.parent == mcglovetarget.parent){
                    if ( txtSearchBox.text != "" ){
                        var searchTarget:DisplayObject = holder.getChildByName(txtSearchBox.text);
                        if (searchTarget){
                            selectMessage(searchTarget);
                            scrollPane.horizontalScrollPosition = searchTarget.x - 220;
                        }else if(1==1){ //if in file
                            gloveCount = aMessages.length;
                            aMessages[gloveCount] = new mcGlove();
                            aMessages[gloveCount] = createMessage(aMessages[gloveCount], txtSearchBox.text, txtSearchBox.text);
                            selectMessage(aMessages[gloveCount]);
                            scrollPane.horizontalScrollPosition = aMessages[gloveCount].x - 220;
                        }else{
                            errorMessage.setAlertText("Sorry, the glove you are searching for does not exist.");
                            addChild(errorMessage);
                        }
                    }
                }else{
                    errorMessage.setAlertText("You must post your message first, otherwise your message will be lost.");
                    addChild(errorMessage);
                }
            }

            function selectMessage(object:mcGlove):void{
                if (showGlove.parent == mcglovetarget.parent){
                    if (activeGloveName != ""){
                        var activeGlove:DisplayObject = holder.getChildByName(activeGloveName);
                        activeGlove.filters = [myDropShadowFilterSmall];
                        activeGlove.scaleX = .28;
                        activeGlove.scaleY = .28;
                        holder.addChild(activeGlove);
                    }
                    activeGloveName = object.name;
                    //event.target.dragIt();
                    holder.addChild(object);
                    object.filters = [new GlowFilter(0xABEEFC, .65, 15, 15, 1, 1, false, false)];
                    object.scaleX = .35;
                    object.scaleY = .35;
                    messageTextField.text = object.getGloveMessage();
                }else{
                    errorMessage.setAlertText("You must post your message first, otherwise your message will be lost.");
                    addChild(errorMessage);
                }
            }

            function releaseMessage(event:MouseEvent):void{
                event.target.dropIt();
            }



            function sortObjects():void{
                addChild(mcglovetarget);
                addChild(scrollPane);
                addChild(pinkline);
                addChild(searchBox);
                addChild(SearchBoxBg);
                addChild(txtSearchBox);
                addChild(txtSearchBox_Label);
                addChild(searchButton);
                addChild(myGlove);
                addChild(topShadowBox);
            }

            myGlove.buttonMode = true;
            searchButton.buttonMode = true;

        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

漫雪独思 2024-07-19 07:49:36

在预加载器主程序中,您像这样实例化程序,

var program:Sprite = new programClass() as Sprite;

我认为您应该这样做:

var program:Sprite = new Program();

请注意,您不需要将程序转换为精灵,因为它已经是精灵了。
ps:你真的在程序构造函数中编写嵌套函数吗? 我的天啊 :-/

in the preloader main, you istantiate the program like this

var program:Sprite = new programClass() as Sprite;

I think you should do:

var program:Sprite = new Program();

Note that you don't need to cast Program as a Sprite, since it is already a Sprite.
ps: are you really writing nested functions in the Program constructor? omg :-/

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