我的循环动画片段不会单击

时间:2014-01-06 06:55:02

标签: actionscript-3 flash actionscript

我一直坚持这个问题,我仍然是AS3的新手,我无法让我的movieclip点击。光标出现,但单击时,它不会执行任何操作。

我想做什么 1.)将JSON数据解析为VO 2.)VO到VectorTest 3a。)JSON数据被分成组,例如box1(list1,name1),Box2(List2,name2)等 3b。)第3个As文件保存VectorTest,当单击任何框时,它会对该框的数据进行会话并转到下一个文件。

但是在点击框时,它什么也没做。

package com.clark
{

    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Stage;
    import fl.controls.Button;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLVariables;
    import flash.utils.*;
    import flash.sampler.NewObjectSample;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
    import flash.text.TextFormatAlign;



       public class searchVO1 extends MovieClip {
        private var Arvariables:URLVariables;
        private var SrSend:URLRequest;
        private var SaLoader:URLLoader;
           public var nobed:String;
        public var zip:String;
        public var Location:String;
        public var price:String;
           public var callMethod:Function;

public var s1:searchpage = new searchpage ();

               public function searchVO1():void{

addEventListener(Event.ADDED_TO_STAGE, onadded);                  // init
function onadded (event:Event):void{


            s1.x=-10;
            s1.y=10;

            addChild(s1);

            // Build the varSend variable
            SrSend = new URLRequest("http://localhost/search.php");
            SrSend.method = URLRequestMethod.POST;
                   Arvariables = new URLVariables;
            SrSend.data = Arvariables;

            SaLoader = new URLLoader();
            SaLoader.dataFormat = URLLoaderDataFormat.TEXT;
            SaLoader.addEventListener(Event.COMPLETE,Asandler);


 // private methods

           function Asandler(event:Event):void{

 // retrieve data from php call
var resultString :String = event.target.data;
// parse result string as json object and cast it to array
var resultArray  :Array  = JSON.parse( resultString ) as Array;
// get the length of the result set
var len:int = resultArray.length;

// create vector of SearchVO
var searchVOs:Vector.<searchVO1> = new Vector.<searchVO1>();
// loop the result array
               var i:int;
for(i=0; i<len; i++ )
{
    searchVOs[i] = new searchVO1();   
    searchVOs[i].nobed = resultArray[i].nobed;
    searchVOs[i].zip = resultArray[i].zip;
    searchVOs[i].Location = resultArray[i].Location;
    searchVOs[i].price =  resultArray[i].price;
}

var mySearchVector:SearchVectorTest = new SearchVectorTest(searchVOs);
addChild(mySearchVector);
       }   
   }
   }

    public function searchVOs( nobed:String, zip:String, location:String, price:String )
        {
            this.nobed      = nobed;
            this.zip        = zip;
            this.Location   = Location;
            this.price      = price;
        }
        public function ValidateAndsearch (event:MouseEvent):void {

        // validate fields

         Arvariables.nobed = s1.nobed.text;
        Arvariables.zip = s1.zip.text;
            Arvariables.Location = s1.Location.text;
            Arvariables.price = s1.price.text;
    SaLoader.load(SrSend);
            var s7:sresultnologin = new sresultnologin()    
    removeChild(s1);
            addChild(s7);


        }

       }

} 

VectorTest

package  com.clark
{
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    public class SearchVectorTest extends MovieClip 
    {
        public var listings:Vector.<Listing8>;

        public function SearchVectorTest(test:Vector.<searchVO1>) 
        {

                for (var j:int = 0; j < test.length; j++) 
            {


                trace(test[j].nobed);
                trace(test[j].zip);
                trace(test[j].Location);
                trace(test[j].price);

        }


            var len:int = test ? test.length : 0;
         // create vector for listings with the len size
         listings = new Vector.<Listing8>(len, true);
            var currentY:int = 100;

            for (var k:int = 0; k < test.length; k++) 
            {
                var Bolder:Listing8 = new Listing8();

                Bolder.x=20;

                var bf:TextField = new TextField();
                var bf1:TextField = new TextField();
                var bf2:TextField = new TextField();
                var bf3:TextField = new TextField();

                bf3.width = 100;
                bf.defaultTextFormat = new TextFormat("Arial", 12, 0, null, null, null, null, null, TextFormatAlign.CENTER);

                bf.width = 100;
                bf.autoSize = TextFieldAutoSize.CENTER;
                bf1.width = 100;
                bf1.autoSize = TextFieldAutoSize.CENTER;
                bf2.autoSize = TextFieldAutoSize.CENTER;
                bf3.autoSize = TextFieldAutoSize.CENTER;
                bf3.width = 100;
                bf1.y= bf.height+5;



                bf.text = test[k].nobed;
                bf1.text = test[k].zip;
                bf2.text = test[k].Location;
                bf3.text = test[k].price;

                bf.x = (Bolder.height-bf.height)*.2
                Bolder.addChild(bf);
                Bolder.addChild(bf1);
                Bolder.addChild(bf2);
                Bolder.addChild(bf3);
                Bolder.properties = test[k].nobed;
                Bolder.properties = test[k].zip;

                Bolder.y = currentY;

                addChild(Bolder);
                 Bolder.mouseChildren = false;    // ignore children mouseEvents
            Bolder.mouseEnabled = true;      // enable mouse on the object - normally set to true by default
            Bolder.useHandCursor = true;     // add hand cursor on mouse over
            Bolder.buttonMode = true; 

                 listings[k] = Bolder;
                currentY += Bolder.height + 10;
            }

        }


    }

}

包含VectorTest的AS文件

package com.clark

{
import com.clark.SearchVectorTest;
    import flash.display.*;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Stage;
    import fl.controls.Button;
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;




       public class sresultnologin extends MovieClip {

public var s1:Searchreult = new Searchreult ();

               public function sresultnologin(){
                  // init



            addEventListener(Event.ADDED_TO_STAGE, onadded);
         function onadded (event:Event):void{



            s1.x=-10;
            s1.y=10;

            addChild(s1);
         }

var s3:SearchVectorTest= new SearchVectorTest(new Vector.<searchVO1>);
                 addChild (s3);


 if( s3.listings.length > 0 )
        {
            // get the first listing in the listing array
            var newListing:Listing8 = s3.listings[0];
            newListing.addEventListener(MouseEvent.CLICK, gotoscener);


        }
        else
        {
                      var newListing1:Listing8= new Listing8
             newListing1.addEventListener(MouseEvent.CLICK, gotoscener);

//

        }


           }

               // private methods
           private function gotoscener(event:MouseEvent):void
        {

            var s9:Listingdetail = new Listingdetail ();    
    removeChild(s1);
            addChild(s9);


       }

}
}

修改

这是函数,尝试进行此单击,但它没有这样做。

这是在代码集上,sresultnologin.as

if( s3.listings.length > 0 )
        {
            // get the first listing in the listing array
            var newListing:Listing8 = s3.listings[0];
            newListing.addEventListener(MouseEvent.CLICK, gotoscener);


        }

0 个答案:

没有答案