2013-01-08 71 views
-1

我得到了一個serius問題,因爲我對as3瞭解不多。將動作從時間線移動到外部.as文件

我有一個項目,在時間軸幀之一,該代碼是ActionScript代碼:

stop(); 


    import flash.display.BitmapData; 
    import flash.display.SimpleButton 
    import flash.display.Bitmap; 
    import flash.display.Loader; 
    import flash.display.MovieClip; 
    import flash.errors.IOError; 
    import flash.events.ProgressEvent; 
    import flash.net.FileFilter; 
    import flash.net.FileReference; 
    import flash.net.URLVariables; 
    import flash.text.TextField; 
    import flash.text.TextFieldType; 
    import flash.utils.ByteArray; 

    import flash.events.MouseEvent; 
    import flash.events.Event; 
    import flash.display.StageAlign; 
    import flash.display.StageScaleMode; 


    import flash.net.URLLoader; 
    import flash.net.URLRequest; 
    import flash.net.URLRequestMethod; 
    import flash.net.URLLoaderDataFormat; 
    import flash.net.URLRequestHeader; 
    import flash.geom.ColorTransform; 

    import flash.geom.Matrix; 
    import flash.display.LoaderInfo; 
    import flash.events.IOErrorEvent; 
    import flash.events.SecurityErrorEvent; 


import com.drooza.*; 
import caurina.transitions.Tweener; 

const thumbWidth:int = 90; 
const numThumbsShown:int = 5; 

var thumb_array:Array = []; 
var thumbContainer:Sprite = new Sprite(), 
    pictureContainer:Sprite = new Sprite(); 

var leftMostThumb:int = 0; //for sliding thumbs 
var currentThumb:int = 0; 
var thumbsXML:XMLReader = new XMLReader("gallery.xml"); 

var thumbcurrentThumbList:XMLList; 
var pictureLoader:Loader; 


//var _browseBtn: SimpleButton; 


thumbsXML.init(); 
thumbsXML.addEventListener(Event.COMPLETE, thumbCompleteHandler); 

pictureContainer.addEventListener(MouseEvent.CLICK, gotoLargePicture); 
pictureContainer.buttonMode = true; 
pictureContainer.mouseChildren = false; 
pictureContainer.x = 10; 
pictureContainer.y = 10; 

addChild(pictureContainer); 
addChildAt(thumbContainer, getChildIndex(mask_mc) - 1); 

with(thumbContainer) 
{ 
    mask = mask_mc; 
    x = mask_mc.x; 
    y = mask_mc.y; 
} 

thumbsXML.parseXML = function() { 
    clearContainer(thumbContainer); 

    try { 
// <gallery albumDir="albums/"> 
// <album galleryDir="album-1/" thumbDir="thumbs/" sizedDir="sized/" largeDir="large/"> 
//  <image url="2009-Lotus-Evora-Front-1280x960.jpg"><![CDATA[Caption for the image 1]]></image> 
     trace(thumbsXML.xmlData..album.length() + " albums found."); 

     for each(var album:XML in thumbsXML.xmlData..album) 
     { 
      trace("ALBUM: \n" + album); 
      for each(var image:XML in album.image) 
      { 
       trace("THUMB\n" + image); 
       //create client thumbs and add them to container 
       var thumb:Thumb = new Thumb(); 
       thumb.imageLoader = new ImageLoader(thumb); 
       thumb.x = (thumbContainer.numChildren * (thumbWidth + 10)); 

       thumb.imageLoader.loadImage([email protected] + [email protected] + [email protected] + [email protected] + [email protected]); 
       thumb.addEventListener(MouseEvent.CLICK, thumbClickHandler); 
       thumbContainer.addChild(thumb); 
       thumb_array[thumb_array.length] = thumb; 

       thumb.item = new Item({ 
         image:[email protected] + [email protected] + [email protected] + [email protected] + [email protected], 
         sized:[email protected] + [email protected] + [email protected] + [email protected] + [email protected], 
         thumb:[email protected] + [email protected] + [email protected] + [email protected] + [email protected], 
         description:image.text() 
         }); 


      } 
     } 

     leftArrow.addEventListener(MouseEvent.CLICK, moveLeft); 
     rightArrow.addEventListener(MouseEvent.CLICK, moveRight); 

     showThumbContents(); 
    } 
    catch(e:Error) 
    { 
     trace(":: Error parsing XML."); 
     trace("Caught: " + e.getStackTrace()); 
    } 
} 





function thumbClickHandler(e:MouseEvent):void { 
    var thumb:Thumb = e.target as Thumb; 
    currentThumb = thumbContainer.getChildIndex(thumb); 
    showThumbContents(); 
} 

function showThumbContents():void { 
    var thumb:Thumb = thumbContainer.getChildAt(currentThumb) as Thumb; 
    clearContainer(pictureContainer); 
    try 
    { 
     pictureLoader = new Loader(); 

     pictureLoader.load(new URLRequest(thumb.item.sized)); 
     pictureLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, IOErrorHandler); 
     pictureLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler); 
     pictureLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, pictureCompleteHandler); 


     pictureContainer.addChild(pictureLoader); 
    } 
    catch(e:TypeError){ 
     trace("Error showing thumb contents.\n\t" + e.getStackTrace()); 
    } 
} 


function gotoLargePicture(e:MouseEvent = null):void { 
    trace("GOTO LARGE PICTURE"); 
    var thumb:Thumb = thumbContainer.getChildAt(currentThumb) as Thumb; 
    navigateToURL(new URLRequest(thumb.item.image), "_blank"); 
} 

function IOErrorHandler(e:IOErrorEvent):void { 
    trace("IOErrorEvent!:" + e); 
} 

function onProgressHandler(e:ProgressEvent):void { 
    trace("ProgressEvent: " + e); 
    loading_mc.visible = true; 
} 

function pictureCompleteHandler(e:Event):void { 
    //trace("Complete! " + e); 
    //pictureContainer.x = 275 - (pictureContainer.width/2) 
    loading_mc.visible = false; 
} 

function adjustThumbs():void { 
    var temp:int = 0; 
    while(temp <= currentThumb - numThumbsShown) 
     temp += numThumbsShown; 
    leftMostThumb = temp; 

    slideThumbs(); 
} 

function moveLeft(e:MouseEvent):void { 
    if(leftMostThumb > 0) 
     leftMostThumb -= numThumbsShown; 
    slideThumbs(); 
} 

function moveRight(e:MouseEvent):void { 
    if(leftMostThumb < int(thumbContainer.numChildren - numThumbsShown)) 
     leftMostThumb += numThumbsShown; 
    slideThumbs(); 
} 

function slideToThumb(thumbNum:int):void { 
    leftMostThumb = thumbNum; 
    slideThumbs(); 
} 

function slideThumbs():void { 
    var slide:Object = {x:mask_mc.x - leftMostThumb * (thumbWidth + 10), time:.5, transition:"easeOut"}; 
    Tweener.addTween(thumbContainer, slide); 
    //Tweener.addTween(clientTitleContainer, slide); 
} 

function prevThumb(e:MouseEvent):void { 
    currentThumb--; 
    if(currentThumb <= 0) 
     currentThumb = thumbContainer.numChildren - 1; 
    //showDescription(); 
    showThumbContents(); 
} 

function nextThumb(e:MouseEvent):void { 
    currentThumb++; 
    if(currentThumb >= thumbContainer.numChildren) 
     currentThumb = 0; 
    //showDescription(); 
    showThumbContents(); 
} 

function clearContainer(container:DisplayObjectContainer):void { 
    while(container.numChildren > 0) 
     container.removeChildAt(0); 
} 

function thumbCompleteHandler(e:Event){ 
    trace("thumbsXML loaded. "); 
    thumbsXML.removeEventListener(Event.COMPLETE, thumbCompleteHandler); 
} 









//_browseBtn = browseBT;// new SimpleButton () ; 
//_browseBtn.useHandCursor = true; 
browseBT.addEventListener (MouseEvent.CLICK, _handleMouseEvent) ; 
//_fileFilter = new FileFilter ("Image", "*.jpg;*.gif;*.png;") ;  


     function _handleMouseEvent (evt : MouseEvent) : void 
     { 

      //_fileRef = new FileReference () ; 
      //_fileRef.browse ([_fileFilter]) ; 
      //_fileRef.addEventListener (Event.SELECT, _onImageSelect) ; 

      blackmask.blackmastin.gotoAndPlay(2); 

     } 

現在我有我想要把這個代碼中的另一個項目,但這個項目從加載ActionScript代碼外部.as文件。

的代碼是:

package 
{ 
    import flash.display.Sprite; 
    import fl.motion.AdjustColor; 
    import flash.filters.ColorMatrixFilter; 
    import fl.events.SliderEvent; 
    import com.flashcube.Transformer; 
    import flash.events.MouseEvent; 


    public class Main extends Sprite 
    { 
     private var color:AdjustColor = new AdjustColor(); 
     private var filter:ColorMatrixFilter; 
     private var faceTransform:Transformer; 

     public function Main():void 
     { 
      /* Required to create initial Matrix */ 

      color.brightness = 0; 
      color.contrast = 0; 
      color.hue = 0; 
      color.saturation = 0; 

      var newZIndex = 10; 

      /* Add Listeners function */ 

      addListeners(); 
      addListeners2(); 
      addListeners22(); 

     } 

     private final function addListeners():void 
     { 
      faceTransform      = new Transformer(image2); 
      faceTransform.color     = 0x000FFF; 
      faceTransform.showCenterCircle  = true; 
      faceTransform.selectedColor   = 0x000000; 
      faceTransform.selectedAlpha   = 0.5; 
      faceTransform.allowScaleProportion = true; 
      faceTransform.allowRotateProportion = false; 

      colorPanel.brightSL.addEventListener(SliderEvent.CHANGE, adjustBrightness); 
      colorPanel.contSL.addEventListener(SliderEvent.CHANGE, adjustContrast); 
      colorPanel.hueSL.addEventListener(SliderEvent.CHANGE, adjustHue); 
      colorPanel.satSL.addEventListener(SliderEvent.CHANGE, adjustSaturation); 


     } 

     private final function adjustBrightness(e:SliderEvent):void 
     { 
      color.brightness = e.target.value; 
      update(); 
     } 

     private final function adjustContrast(e:SliderEvent):void 
     { 
      color.contrast = e.target.value; 
      update(); 
     } 

     private final function adjustHue(e:SliderEvent):void 
     { 
      color.hue = e.target.value; 
      update(); 
     } 

     private final function adjustSaturation(e:SliderEvent):void 
     { 
      color.saturation = e.target.value; 
      update(); 
     } 

     private final function update():void 
     { 
      filter = new ColorMatrixFilter(color.CalculateFinalFlatArray()); 
      image.filters = [filter]; 
     } 







     private final function addListeners2():void 
     { 
      colorPanel2.brightSL.addEventListener(SliderEvent.CHANGE, adjustBrightness2); 
      colorPanel2.contSL.addEventListener(SliderEvent.CHANGE, adjustContrast2); 
      colorPanel2.hueSL.addEventListener(SliderEvent.CHANGE, adjustHue2); 
      colorPanel2.satSL.addEventListener(SliderEvent.CHANGE, adjustSaturation2); 
     } 

     private final function adjustBrightness2(e:SliderEvent):void 
     { 
      color.brightness = e.target.value; 
      update2(); 
     } 

     private final function adjustContrast2(e:SliderEvent):void 
     { 
      color.contrast = e.target.value; 
      update2(); 
     } 

     private final function adjustHue2(e:SliderEvent):void 
     { 
      color.hue = e.target.value; 
      update2(); 
     } 

     private final function adjustSaturation2(e:SliderEvent):void 
     { 
      color.saturation = e.target.value; 
      update2(); 
     } 

     private final function update2():void 
     { 
      filter = new ColorMatrixFilter(color.CalculateFinalFlatArray()); 
      image2.filters = [filter]; 
     } 


    //------------------------------------------------- 

private final function addListeners22():void 
     { 
image.addEventListener(MouseEvent.CLICK, friendMaker); 
     } 

private final function friendMaker(evt:MouseEvent):void { 
//setChildIndex(image2,stage.numChildren-1); 
    setChildIndex(image,numChildren+1); 
} 





    } 

} 

請爲它可能是有人幫我混的第一個代碼INT第二。至於文件?

我附加了所有源文件的下載鏈接。

在文件AdgustColor in frame上有我想要傳送到Main.as文件的動作代碼。

在filescroller.fla中有原始的Scroller。

Ofcourse的AdgustColor.fla不工作,直到我從時間軸幀刪除ActionScript代碼1.

下載:myfiles

回答

1

我要老實跟你在這裏。你應該從小處着手,閱讀一些關於類如何工作的教程,然後再嘗試這樣的事情。雖然遷移非常容易,但當需要以任何方式修改代碼時,您都會遇到問題。

+0

當然,你是正確的lostPixels,但在我的情況下是否有任何可能幫助我? –

0

如果你不知道自己在做什麼,那麼特別是從類文件中「混合」代碼並不是一個好主意。我不認爲這裏的任何人都能以你想要的方式回答這個問題,這似乎是「只爲我做」。也許如果你提供什麼最終結果會有人可能會爲你做。那裏有很多代碼,所以我仍然懷疑你會得到一個完美的答案。我認爲你將得到的最佳答案是深入研究代碼並學習它的功能。最終你會得到一個更好的結果,因爲你會知道關於代碼的一切,你會從中學到一些東西,你可以應用於其他問題。希望有所幫助!

+0

好吧,我混了起來,它的工作很棒。感謝您的時間! –

相關問題