好的,所以我得到了这个演示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()
您能否澄清 - 您是否希望不仅摆脱外部XML,而且还摆脱外部图像,这意味着图像将被嵌入到swf中? – redhotvengeance 2012-02-18 22:26:30
是的确切而不是从XML加载从嵌入式图像加载,但保持效果,据我所知,这加载图像在XML中的数组,然后它使用该数组的效果? – Andres 2012-02-19 05:37:57