2012-02-18 66 views
0

好的,所以我得到了這個演示Flash文件,它通過XML加載圖像並添加不同的效果。目前它被用作頁面上的橫幅。現在我被要求保留效果,但要在Flash中嵌入圖片(這樣才能擺脫XML)。我無法知道如何將其更改爲不從XML讀取。任何幫助將不勝感激,因爲我停止使用閃回在MX時代...:SFlash加載圖像不使用XML

import caurina.transitions.Tweener; 
import caurina.transitions.properties.ColorShortcuts; 
import flash.events.MouseEvent; 

ColorShortcuts.init(); 

var hover_effect:Boolean; 
var auto_play:Boolean; 
var auto_play_duration:Number = 3000; 
var no_of_rows:uint = 4; 
var no_of_columns:uint = 8; 

var tween_duration:Number = 0.7; 
var tween_delay:Number = 0.03; 
var block_scale:Number = 0.1; 
var flashmo_margin:Number = 10; 
var offstage_position:Number = 300; 

var i:Number; 
var j:Number; 
var new_x:Number; 
var new_y:Number; 
var pic:Number = 0; 
var previous_no:Number = 0; 
var current_no:Number = 0; 
var total:Number; 

var timer:Timer; 
var flashmo_xml:XML; 
var flashmo_photo_list = new Array(); 
var mc:MovieClip; 
var photo_group:MovieClip = new MovieClip(); 
var circle_group:MovieClip = new MovieClip(); 
var photo_array:Array; 
var photo_group_array:Array; 
var size_width:uint; 
var size_height:uint; 
var photo_width:uint; 
var photo_height:uint; 

stage.scaleMode = StageScaleMode.NO_SCALE; 
stage.align = StageAlign.TOP_LEFT; 

photo_group.mask = flashmo_photo_area; 
photo_group_array = []; 
photo_button.alpha = 0; 
flashmo_cover.visible = false; 
flashmo_bar.flashmo_next.visible = false; 
flashmo_bar.flashmo_previous.visible = false; 
flashmo_bar.flashmo_play.visible = false; 
flashmo_bar.flashmo_pause.visible = false; 

flashmo_bar.addChild(circle_group); 
this.addChildAt(photo_group, 1); 
this.addChild(photo_button); 
this.addChild(flashmo_bar); 

function load_gallery(xml_file:String):void 
{ 

create_photo_rotator(); 
} 

//remove argument since it is no longer being passed the Event 
function create_photo_rotator():void 
{ 
    //manually set a bunch of properties that the XML normally would have 
    hover_effect=true; 
    auto_play=true; 
    auto_play_duration=2.4; 
    //grid_row=3; 
    //grid_column=9; 
    tween_duration=0.7; 
    tween_delay=0.03; 

    //manually build array of photo objects 
    //notice that "Photo1" is the filename, same as the photo Class name we set above 
    //add as many of this code block as there are embedded photos 
    flashmo_photo_list.push({ 
     filename: "slide1", 
     flow: "in", 
     direction: "right", 
     rotation: "" 
    }); 

    flashmo_photo_list.push({ 
     filename: "slide2", 
     flow: "in", 
     direction: "left", 
     rotation: "" 
    }); 

    flashmo_photo_list.push({ 
     filename: "slide3", 
     flow: "in", 
     direction: "down", 
     rotation: "-180" 
    }); 

    flashmo_photo_list.push({ 
     filename: "slide4", 
     flow: "in", 
     direction: "up", 
     rotation: "" 
    }); 

    total = flashmo_photo_list.length; 

    load_photo(); 

} 

function load_photo():void 
{ 
    //manually call on_photo_loaded and pass it current photo index 
    on_photo_loaded(pic); 
    pic++; 

    load_circle(); 

} 

function load_circle():void 
{ 
    var fm_circle:MovieClip = new flashmo_circle(); 
    fm_circle.x = 5 + (fm_circle.width + 4) * (pic - 1) + fm_circle.width * 0.5; 
    fm_circle.y = (flashmo_bar.bar.height - fm_circle.height) * 0.5; 
    fm_circle.name = "flashmo_circle_" + circle_group.numChildren; 
    fm_circle.visible = false; 
    circle_group.addChild(fm_circle); 

    if(circle_group.numChildren == 1) 
    {  
     Tweener.addTween(fm_circle , { _color_redOffset: 255, _color_greenOffset: 255, 
        _color_blueOffset: 255, time: tween_duration, transition: "easeIn" }); 
    } 
} 

function on_photo_progress(e:ProgressEvent):void 
{ 
    var percent:Number = Math.round(e.bytesLoaded/e.bytesTotal * 100); 

} 

//change argument to expect photo index instead of Event 
function on_photo_loaded(photoIndex:int):void 
{ 
    mc = MovieClip(circle_group.getChildAt(pic - 1)); 
    mc.visible = true; 

    //create Bitmap from embedded image's BitmapData 
    var photoBitmap:Bitmap = new Bitmap(flashmo_photo_list[photoIndex].filename); 

    if(pic == 1) 
    { 
     //adjust values on newly created Bitmap 
     photo_width = photoBitmap.width; 
     photo_height = photoBitmap.height; 

     adjust_size(); 
    } 
    else if(pic > 1) 
    { 
     enable_circle(mc); 

     if(pic == 2) 
     { 
      flashmo_bar.flashmo_previous.addEventListener(MouseEvent.CLICK, pic_previous); 
      flashmo_bar.flashmo_next.addEventListener(MouseEvent.CLICK, pic_next);    
      flashmo_bar.flashmo_play.addEventListener(MouseEvent.CLICK, pic_play); 
      flashmo_bar.flashmo_pause.addEventListener(MouseEvent.CLICK, pic_pause); 
      flashmo_bar.flashmo_previous.visible = flashmo_bar.flashmo_next.visible = true; 

      timer = new Timer(auto_play_duration); 
      timer.addEventListener(TimerEvent.TIMER, auto_play_timer); 

      if(auto_play) 
      { 
       flashmo_bar.flashmo_play.visible = false; 
       flashmo_bar.flashmo_pause.visible = true; 

       timer.start(); 
      } 
      else 
      { 
       flashmo_bar.flashmo_play.visible = true; 
       flashmo_bar.flashmo_pause.visible = false; 
      }   
     } 
    } 

    if(pic < total) 
    { 
     load_photo(); 
    } 

    //pass the Bitmap to create_effect (which is already expecting a Bitmap) 
    create_effect(photoBitmap); 

} 

function adjust_size():void 
{ 
    flashmo_photo_area.width = photo_button.width = flashmo_bar.bar.width = photo_width; 
    flashmo_photo_area.height = photo_button.height = photo_height; 

    flashmo_bar.flashmo_next.x = 
      flashmo_bar.bar.width - flashmo_bar.flashmo_next.width - flashmo_margin * 0.5; 

    flashmo_bar.flashmo_previous.x = flashmo_bar.flashmo_next.x - flashmo_bar.flashmo_next.width; 

    flashmo_bar.flashmo_play.x = flashmo_bar.flashmo_pause.x = 
      flashmo_bar.flashmo_previous.x - flashmo_bar.flashmo_previous.width; 

    flashmo_bar.y = photo_height; 
    photo_group.x = flashmo_photo_area.x; 
    photo_group.y = flashmo_photo_area.y; 
    photo_group.mask = flashmo_photo_area; 
} 

function create_effect(bitmap:Bitmap):void 
{ 
    var flashmo_pic_mc:MovieClip = new MovieClip(); 

    size_width = Math.ceil(photo_width/no_of_columns); 
    size_height = Math.ceil(photo_height/no_of_rows); 
    photo_array = []; 

    if(photo_group.x == flashmo_photo_area.x) 
    { 
     photo_group.x += size_width * 0.5; 
     photo_group.y += size_height * 0.5; 
    } 

    for(j = 0; j < no_of_rows; j++) 
    { 
     for(i = 0; i < no_of_columns; i++) 
     {              
      var temp_bitmap_data:BitmapData = new BitmapData (size_width, size_height, true, 0xFFFFFF); 
      var source_rect:Rectangle = new Rectangle (i * size_width, j * size_height, 
                 size_width, size_height); 

      temp_bitmap_data.copyPixels (bitmap.bitmapData, source_rect, new Point); 

      var temp_bitmap:Bitmap = new Bitmap (temp_bitmap_data); 
      var temp_sprite:Sprite = new Sprite; 

      temp_bitmap.smoothing = true; 
      temp_bitmap.x = - temp_bitmap.width * 0.5; 
      temp_bitmap.y = - temp_bitmap.height * 0.5; 

      temp_sprite.addChild (temp_bitmap); 
      temp_sprite.x = i * size_width; 

      if(photo_group.numChildren > 0) 
       temp_sprite.y = photo_height; 
      else 
       temp_sprite.y = j * size_height; 

      photo_array.push (temp_sprite); 
      flashmo_pic_mc.addChild(temp_sprite); 
     } 
    } 

    flashmo_pic_mc.name = "flashmo_pic_" + photo_group.numChildren; 
    photo_group_array.push(photo_array); 
    photo_group.addChild (flashmo_pic_mc); 
} 

function auto_play_timer(te:TimerEvent):void 
{ 
    current_no++; 
    change_photo(); 
} 

function change_photo():void 
{ 
    if(current_no >= photo_group.numChildren) 
     current_no = 0; 
    if(current_no < 0) 
     current_no = photo_group.numChildren - 1; 

    var flashmo_direction:String = flashmo_photo_list[current_no].direction; 
    var flashmo_rotation_str:String = flashmo_photo_list[current_no].rotation; 
    var flashmo_rotation:Number = 0; 

    if(flashmo_direction == "") 
     flashmo_direction = "center"; 

    if(flashmo_rotation_str != "") 
     flashmo_rotation = parseInt(flashmo_rotation_str); 

    if(flashmo_photo_list[current_no].flow == "in") 
     transition_in(current_no, flashmo_direction, flashmo_rotation); 
    else 
     transition_out(previous_no, flashmo_direction, flashmo_rotation); 

    disable_buttons(); 
} 

function transition_in(pic_index:uint, from_direction:String, flashmo_rotation:Number):void 
{ 
    photo_group.addChild(photo_group.getChildByName("flashmo_pic_" + pic_index)); 
    photo_array = photo_group_array[ pic_index ]; 

    var row_no:uint; 
    var column_no:uint; 

    for (i = 0; i < photo_array.length ; i++) 
    {  
     if(flashmo_rotation != 0) 
      photo_array[i].rotation = flashmo_rotation; 

     photo_array[i].scaleX = photo_array[i].scaleY = block_scale; 
     photo_array[i].alpha = 0; 

     if(from_direction == "left") 
     { 
      photo_array[i].x = - size_width;    
      photo_array[i].y = Math.floor(i/no_of_columns) * size_height; 
     } 
     else if(from_direction == "right") 
     { 
      photo_array[i].x = photo_width; 
      photo_array[i].y = Math.floor(i/no_of_columns) * size_height; 
     } 
     else if(from_direction == "up") 
     { 
      photo_array[i].x = (i % no_of_columns) * size_width ; 
      photo_array[i].y = - size_height; 
     } 
     else if(from_direction == "down") 
     { 
      photo_array[i].x = (i % no_of_columns) * size_width; 
      photo_array[i].y = photo_height; 
      photo_array[i].scaleX = photo_array[i].scaleY = 0; 
     } 
     else 
     { 
      photo_array[i].x = (i % no_of_columns) * size_width; 
      photo_array[i].y = Math.floor(i/no_of_columns) * size_height;   
     } 
    } 

    for (i = 0; i < photo_array.length ; i++) 
    {  
     if(from_direction == "left") 
     { 
      j = photo_array.length - i - 1; 
      j = (j % no_of_rows) * no_of_columns + Math.floor(j/no_of_rows); 

      new_x = (j % no_of_columns) * size_width; 
      new_y = photo_array[j].y; 
     } 
     else if(from_direction == "right") 
     { 
      j = (i % no_of_rows) * no_of_columns + Math.floor(i/no_of_rows); 
      new_x = (j % no_of_columns) * size_width; 
      new_y = photo_array[j].y; 
     } 
     else if(from_direction == "up") 
     { 
      j = photo_array.length - i - 1; 
      new_x = photo_array[j].x; 
      new_y = Math.floor(j/no_of_columns) * size_height; 
     } 
     else if(from_direction == "down") 
     { 
      j = i; 
      new_x = photo_array[j].x; 
      new_y = Math.floor(j/no_of_columns) * size_height; 
     } 
     else 
     { 
      j = i; 
      new_x = photo_array[j].x; 
      new_y = photo_array[j].y; 
     } 

     Tweener.addTween (photo_array[j], { x: new_x, y: new_y, 
      alpha: 1, scaleX: 1, scaleY: 1, rotation: 0, 
      delay: tween_delay * i, time: tween_duration, transition: "easeOutQuart", 
      onComplete: transition_complete, onCompleteParams:[i, true] } ); 
    } 
} 

function transition_complete(no:Number, transition_in:Boolean):void 
{ 
    if(no == photo_array.length - 1) 
    {  
     if(transition_in) 
     { 
      photo_array = photo_group_array[ previous_no ]; 

      var sprite_index:Number = 0; 

      for (j = 0; j < no_of_rows; j++) 
      { 
       for (i = 0; i < no_of_columns; i++) 
       { 
        photo_array[ sprite_index ].x = -1000; 
        photo_array[ sprite_index ].y = -1000;   
        sprite_index++;   
       } 
      } 
     } 

     enable_buttons(); 
    } 
} 

function transition_out(pic_index:uint, to_direction:String, flashmo_rotation:Number):void 
{ 
    photo_group.addChild(photo_group.getChildByName("flashmo_pic_" + current_no)); 
    photo_group.addChild(photo_group.getChildByName("flashmo_pic_" + pic_index)); 
    photo_array = photo_group_array[ pic_index ]; 

    var flashmo_effect:String = "easeInQuart"; 

    for (i = 0; i < photo_array.length ; i++) 
    {  
     if(to_direction == "left") 
     { 
      j = (i % no_of_rows) * no_of_columns + Math.floor(i/no_of_rows); 
      new_x = - offstage_position; 
      new_y = photo_array[j].y; 
     } 
     else if(to_direction == "right") 
     { 
      j = photo_array.length - i - 1; 
      j = (j % no_of_rows) * no_of_columns + Math.floor(j/no_of_rows); 
      new_x = photo_width + offstage_position; 
      new_y = photo_array[j].y; 
     }  
     else if(to_direction == "up") 
     { 
      j = i; 
      new_x = photo_array[j].x; 
      new_y = - offstage_position; 
     } 
     else if(to_direction == "down") 
     { 
      j = photo_array.length - i - 1; 
      new_x = photo_array[j].x; 
      new_y = photo_height + offstage_position;   
     } 
     else 
     { 
      j = i; 
      new_x = photo_array[j].x; 
      new_y = photo_array[j].y; 
      flashmo_effect = "easeInOutQuart"; 
     } 

     Tweener.addTween (photo_array[j], { x: new_x, y: new_y, 
      scaleX: block_scale, scaleY: block_scale, alpha: 0, rotation: flashmo_rotation, 
      delay: tween_delay * i, time: tween_duration, transition: flashmo_effect, 
      onComplete: transition_complete, onCompleteParams:[i, false] }); 
    } 

    to_normal_position(current_no); 
} 

function to_normal_position(pic_index:uint):void 
{ 
    photo_array = photo_group_array[ pic_index ]; 

    var sprite_index:Number = 0; 

    for (j = 0; j < no_of_rows; j++) 
    { 
     for (i = 0; i < no_of_columns; i++) 
     { 
      photo_array[ sprite_index ].rotation = 0; 
      photo_array[ sprite_index ].alpha = 
      photo_array[ sprite_index ].scaleX = 
      photo_array[ sprite_index ].scaleY = 1;   
      photo_array[ sprite_index ].x = i * size_width; 
      photo_array[ sprite_index ].y = j * size_height;    
      sprite_index++;   
     } 
    } 
} 


function pic_over(e:MouseEvent):void 
{ 
    Tweener.addTween(photo_button, { alpha: 0.15, time: tween_duration, transition: "easeIn" }); 
} 

function pic_out(e:MouseEvent):void 
{ 
    Tweener.addTween(photo_button, { alpha: 0, time: tween_duration, transition: "easeOut" }); 
} 

function pic_previous(e:MouseEvent):void 
{ 
    current_no--; 
    change_photo(); 
} 

function pic_next(e:MouseEvent):void 
{ 
    current_no++; 
    change_photo(); 
} 

function pic_play(e:MouseEvent):void 
{ 
    flashmo_bar.flashmo_pause.visible = true; 
    flashmo_bar.flashmo_play.visible = false; 
    auto_play = true; 

    if(circle_group.alpha == 1) 
     timer.start(); 
} 

function pic_pause(e:MouseEvent):void 
{ 
    flashmo_bar.flashmo_pause.visible = false; 
    flashmo_bar.flashmo_play.visible = true; 
    auto_play = false; 
    timer.reset(); 
} 

function circle_out(me:MouseEvent):void 
{ 
    mc = MovieClip(me.target); 
    Tweener.addTween(mc, { _color_redOffset: 0, _color_greenOffset: 0, 
        _color_blueOffset: 0, time: tween_duration, transition: "easeIn" }); 
} 

function circle_over(me:MouseEvent):void 
{ 
    mc = MovieClip(me.target); 
    Tweener.addTween(mc, { _color_redOffset: 255, _color_greenOffset: 255, 
        _color_blueOffset: 255, time: tween_duration, transition: "easeIn" }); 
} 

function circle_click(me:MouseEvent):void 
{ 
    mc = MovieClip(me.target); 
    current_no = parseInt(mc.name.slice(15,17)); 
    change_photo(); 
} 

function enable_buttons():void 
{ 
    if(auto_play) 
     timer.start(); 
    else 
     timer.reset(); 

    photo_button.visible = true; 
    flashmo_bar.flashmo_previous.mouseEnabled = true; 
    flashmo_bar.flashmo_next.mouseEnabled = true; 

    flashmo_bar.flashmo_previous.addEventListener(MouseEvent.CLICK, pic_previous); 
    flashmo_bar.flashmo_next.addEventListener(MouseEvent.CLICK, pic_next); 
    circle_group.alpha = 1; 

    for(i = 0; i < circle_group.numChildren; i++) 
    { 
     if(i == current_no) 
      continue; 

     mc = MovieClip(circle_group.getChildAt(i)); 
     enable_circle(mc); 
    } 

    previous_no = current_no; 
} 

function disable_buttons():void 
{ 
    if(auto_play) 
     timer.reset(); 

    photo_button.visible = false; 
    flashmo_bar.flashmo_previous.mouseEnabled = false; 
    flashmo_bar.flashmo_next.mouseEnabled = false; 

    flashmo_bar.flashmo_previous.removeEventListener(MouseEvent.CLICK, pic_previous); 
    flashmo_bar.flashmo_next.removeEventListener(MouseEvent.CLICK, pic_next); 
    circle_group.alpha = 0.5; 

    for(i = 0; i < circle_group.numChildren; i++) 
    { 
     mc = MovieClip(circle_group.getChildAt(i)); 
     disable_circle(mc); 
     Tweener.addTween(mc, { _color_redOffset: 0, _color_greenOffset: 0, 
        _color_blueOffset: 0, time: tween_duration, transition: "easeIn" }); 
    } 

    mc = MovieClip(circle_group.getChildAt(current_no)); 
    Tweener.addTween(mc , { _color_greenOffset: 255, _color_redOffset: 255, 
        _color_blueOffset: 255, time: tween_duration, transition: "easeIn" }); 
} 

function enable_circle(mc:MovieClip):void 
{ 
    mc.addEventListener(MouseEvent.CLICK, circle_click); 
    mc.addEventListener(MouseEvent.MOUSE_OUT, circle_out); 
    mc.addEventListener(MouseEvent.MOUSE_OVER, circle_over); 
    mc.buttonMode = true; 
} 

function disable_circle(mc:MovieClip):void 
{ 
    mc.removeEventListener(MouseEvent.CLICK, circle_click); 
    mc.removeEventListener(MouseEvent.MOUSE_OUT, circle_out); 
    mc.removeEventListener(MouseEvent.MOUSE_OVER, circle_over); 
    mc.buttonMode = false; 
} 


Object(root).grid_slider.logo.cotton.addEventListener(MouseEvent.CLICK,fl_ClickToGoToWebPage); 
function fl_ClickToGoToWebPage(event:MouseEvent):void 
{ 
    navigateToURL(new URLRequest("http://www.google.com"), "_self"); 
} 

更新的代碼與新的錯誤:

TypeError: Error #1010: A term is undefined and has no properties. 
at original_fla::GridSliderClick_1/create_photo_rotator() 
at original_fla::GridSliderClick_1/load_gallery() 
at original_fla::MainTimeline/frame1() 
+1

您能否澄清 - 您是否希望不僅擺脫外部XML,而且還擺脫外部圖像,這意味着圖像將被嵌入到swf中? – redhotvengeance 2012-02-18 22:26:30

+0

是的確切而不是從XML加載從嵌入式圖像加載,但保持效果,據我所知,這加載圖像在XML中的數組,然後它使用該數組的效果? – Andres 2012-02-19 05:37:57

回答

2

有幾件事情你必須做將其轉換爲不使用XML和外部圖像。我會盡我所能地引導你,但是我沒有很多基於你提供的代碼的信息(例如,我沒有看到這段代碼是如何初始化的,因爲它看起來像loadGallery()正在由未張貼的東西調用)。

你需要做的第一件事是嵌入所有的外部圖像。要做到這一點,您需要使用文件>導入>導入庫來將圖像導入到Flash庫中...

將所有圖像導入庫後,庫現在應該有一個位圖和一個符號爲每個圖像。忽視或刪除符號 - 你不需要它們。右鍵單擊每個位圖,然後打開屬性。在這裏,命名頂部對話框中的位圖(例如,Photo1),然後在「鏈接」區域中單擊「導出爲ActionScript」按鈕。 「類」對話框應該自動填充位圖名稱(例如,Photo1),「基類」對話框應該是flash.display.BitmapData

圖像現在將嵌入到swf中 - 您所做的是將每個圖像轉換爲可通過ActionScript訪問的BitmapData類。現在,您需要更改代碼以使用這些嵌入式圖像,而不是外部圖像。

轉換此代碼的一個挑戰是代碼嚴重依賴於XML。

它看起來像我的代碼初始化通過調用方法load_gallery()的東西。但是,我不知道這是什麼。所以保持這種方法,但只是將其去掉:

function load_gallery(xml_file:String):void 
{ 
    create_photo_rotator(); 
} 

這將繞過加載XML。接下來,你需要大量修改create_photo_rotator()方法:

//remove argument since it is no longer being passed the Event 
function create_photo_rotator():void 
{ 
    //manually set a bunch of properties that the XML normally would have 
    hover_effect = <set true or false>; 
    auto_play = <set true or false>; 
    auto_play_duration = <set number>; 
    no_of_rows = <set number>; 
    no_of_columns = <set number>; 
    tween_duration = <set number>; 
    tween_delay = <set number>; 

    //manually build array of photo objects 
    //notice that "Photo1" is the filename, same as the photo Class name we set above 
    //add as many of this code block as there are embedded photos 
    //**UPDATE**:store an instance of the BitmapData class instead of the name of the class as a string - notice the key name has changed to "bitmapData" instead of "filename" 
    flashmo_photo_list.push({ 
     bitmapData: new Photo1(), 
     flow: "<flow string>", 
     direction: "<direction string>", 
     rotation: "<rotation string>" 
    }); 

    total = flashmo_photo_list.length; 

    load_photo(); 
} 

更新:
基本上,你必須手工打造出來的照片數據的陣列的,因爲你不再有XML。只需複製推送對象數據的代碼塊到flashmo_photo_list中即可獲取儘可能多的照片。確保將bitmapData分別設置爲您之前嵌入的相關位圖類的新實例,然後手動設置其他屬性(只需通過XML並複製它們設置的位置)。因此,如果在庫中有一個名爲「Photo1」的位圖,並且在Photo1的屬性中單擊了「爲ActionScript導出」並將「類」設置爲「Photo1」,則代碼將爲:bitmapData: new Photo1()

現在,改變load_photo()方法實際上移除加載照片:

function load_photo():void 
{ 
    //manually call on_photo_loaded and pass it current photo index 
    on_photo_loaded(pic); 
    pic++; 

    load_circle(); 
} 

最後,改變on_photo_loaded()使用嵌入式位圖:

//change argument to expect photo index instead of Event 
function on_photo_loaded(photoIndex:int):void 
{ 
    mc = MovieClip(circle_group.getChildAt(pic - 1)); 
    mc.visible = true; 

    //create Bitmap from embedded image's BitmapData 
    //**UPDATE**: reference the stored bitmapData instead of filename string 
    var photoBitmap:Bitmap = new Bitmap(flashmo_photo_list[photoIndex].bitmapData); 

    if(pic == 1) 
    { 
     //adjust values on newly created Bitmap 
     photo_width = photoBitmap.width; 
     photo_height = photoBitmap.height; 

     adjust_size(); 
    } 
    else if(pic > 1) 
    { 
     enable_circle(mc); 

     if(pic == 2) 
     { 
      flashmo_bar.flashmo_previous.addEventListener(MouseEvent.CLICK, pic_previous); 
      flashmo_bar.flashmo_next.addEventListener(MouseEvent.CLICK, pic_next);    
      flashmo_bar.flashmo_play.addEventListener(MouseEvent.CLICK, pic_play); 
      flashmo_bar.flashmo_pause.addEventListener(MouseEvent.CLICK, pic_pause); 
      flashmo_bar.flashmo_previous.visible = flashmo_bar.flashmo_next.visible = true; 

      timer = new Timer(auto_play_duration); 
      timer.addEventListener(TimerEvent.TIMER, auto_play_timer); 

      if(auto_play) 
      { 
       flashmo_bar.flashmo_play.visible = false; 
       flashmo_bar.flashmo_pause.visible = true; 

       timer.start(); 
      } 
      else 
      { 
       flashmo_bar.flashmo_play.visible = true; 
       flashmo_bar.flashmo_pause.visible = false; 
      }   
     } 
    } 

    if(pic < total) 
    { 
     load_photo(); 
    } 

    //pass the Bitmap to create_effect (which is already expecting a Bitmap) 
    create_effect(photoBitmap); 
} 

你正在做一個new Bitmap的原因是因爲您之前嵌入的照片導出爲BitmapData類,所以您使用該BitmapData來創建照片Bitmap已更新:請確保您引用對象上的「bitmapData」值而不是以前使用的「文件名」值。

根據您提供的代碼,這些更改應完成您所要求的內容。但是,我無法自己測試,所以你可能仍然需要調整一些東西。

+0

**免責聲明:**由於您發佈的原始代碼非常糟糕,我的建議是重寫整個事情。但是如果你的背部靠牆,希望上述建議能幫助你。請記住,這些變化充其量只是「冒險」,並且認爲它們是「緊急事件」,因爲它們實際上不是最佳實踐(最佳實踐可能需要對整個項目進行重大改革)。 – redhotvengeance 2012-02-19 18:53:49

+0

好吧,一切都應該如此,但現在即時通過我的導入錯誤:import caurina.transitions.Tweener; 它說的是它找不到? – Andres 2012-02-22 05:40:42

+0

這個錯誤只是在您做出更改後纔開始?您是否移動FLA或刪除任何內容?編譯器因爲找不到Tweener類而引發錯誤。 FLA旁邊應該有一個名爲「caurina」的文件夾。如果你找不到它,那麼你可以在這裏下載它:http://code.google.com/p/tweener/downloads/detail?name=tweener_1_33_74_as3.zip – redhotvengeance 2012-02-22 19:33:39