2013-07-08 30 views
1

嘿同胞程序員....首先我想說我有這個工作之前,我試圖導入到我的主類,但現在它的破產....我只是想得到這productselection class鏈接和工作在barrelbuilder class非常感謝您提前尋求任何幫助,因爲我只是通過不同的錯誤試圖修復它。試圖打電話自定義類

BarrelBuilder.as 
package { 

import flash.net.*; 
import flash.display.MovieClip; 
import flash.events.Event; 
import flash.display.Loader; 
import flash.xml.*; 
import utils.ProductSelection; 


public class BarrelBuilder extends MovieClip{ 

    var PSelection:ProductSelection; 

public function BarrelBuilder():void 
    { 

     PSelection.ProductSelection(); 

    } 
} 

} 


ProductSelection.as 

package utils 
{ 

import flash.net.*; 
import flash.display.MovieClip; 
import flash.events.Event; 
import flash.display.Loader; 
import flash.xml.*; 


public class ProductSelection extends MovieClip{ 
    private static var columns:Number; 
    private static var my_x:Number; 
    private static var my_y:Number; 
    private static var my_thumb_width:Number; 
    private static var my_thumb_height:Number; 
    private static var my_images:XMLList; 
    private static var my_total:Number; 

    private static var container_mc:MovieClip; 

    private static var myXMLLoader:URLLoader = new URLLoader(); 



    public static function ProductSelections(stage:Object){ 
    init(stage); 

    } 

    public static function init(stage:Object) 
    { 
     myXMLLoader.load(new URLRequest("resources.xml")); 
     myXMLLoader.addEventListener(Event.COMPLETE, processXML(stage)); 


     function processXML (e:Event):void{ 
      var myXML:XML = new XML(e.target.data); 

      columns = [email protected]; 
      my_x = [email protected]; 
      my_y = [email protected]; 
      my_thumb_width = [email protected]; 
      my_thumb_height = [email protected]; 
      my_images = myXML.IMAGE; 
      my_total = my_images.length(); 

      createContainer(stage); 
      callThumbs(); 

      } 
    } 
    public static function createContainer(stage:Object):void{ 
     container_mc = new MovieClip(); 
     container_mc.x = my_x; 
     container_mc.y = my_y; 
     //container_mc.height = 50; 
     //container_mc.width = 140; 
     stage.addChild(container_mc); 
    } 
    public static function callThumbs():void{ 
     for (var i:Number = 0; i < my_total; i++){ 

     var thumb_url = my_images[i][email protected];; 
     var thumb_loader = new Loader(); 
     thumb_loader.load(new URLRequest(thumb_url)); 
     thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded); 

     thumb_loader.x = (my_thumb_width+10)*i; 
     } 
    } 
    public static function thumbLoaded(e:Event):void{ 
     var my_thumb:Loader = Loader(e.target.loader); 
     container_mc.addChild(my_thumb); 
     //my_thumb.addEventListener(Mouse.CLICK, thumb_Clicked); 
    } 

    //thumbClicked() 
    //{ 

    //} 
} 

} 

回答

0

試試這個:

PSelection = new ProductSelection(stage); 

會工作,如果BarrelBuilder是你的 「主要」 類。

如果沒有

public function BarrelBuilder():void 
{ 
    addEventListener(Event.ADDED_TO_STAGE,onAddedToStage) 
} 
private function onAddedToStage(e:Event):void 
{ 
    removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage); 
    PSelection = new ProductSelection(stage); 
} 

見我初始化類的基本解釋here