セットアップ
AとBの2 つの SWF があります。Aは、 Aの子として追加されるBの単純なプリローダーです。Bは、私が作成したフォト ギャラリーを作成するカスタム クラスを使用します。これをCと呼びます。独自のクラスを作成するのはこれが初めてなので、ご容赦ください :/
問題
Aをテストすると、次のエラーが発生します。
ReferenceError: Error #1065: Variable ScrollEvent is not defined.
at MethodInfo-4757()
at MethodInfo-4748()
これが特に混乱を招く理由はいくつかあります。まず、Cで(従うべきコード)ScrollEvent
が定義されます。次に、BのライブラリにはUIScrollBar
and ProgressBar
( Cも使用するもの) コンポーネントがありますが、 AのライブラリにScrollBar
andProgressBar
コンポーネントを追加すると、エラーは消えますが、結果の SWF はAのコンポーネントを使用しており、カスタム スキンのコンポーネントは使用していません。B. _ これにはおそらく明らかな答えがありますが、私はこれにかなり困惑しているので、助けていただければ幸いです!
B - Aによってロードされ、 Cのインスタンスを作成するメインの SWF 。プロジェクトではclaudia.asとして知られています
コードが長すぎるため、すべてのコードを掲載することはできません。そのため、BでCのインスタンスを作成する方法を次に示します。
public function pg3_setup():void
{
var address:String = "flash_scripts/photo_gallery.xml";
var gallery:claudeGallery = new claudeGallery(address,bg.width - p_pad_left - p_pad_right,bg.height - p_pad_top - p_pad_bottom,true,des_array[2],init_array);
gallery.addEventListener("SETUP_COMPLETE",g_complete);
function g_complete(e:Event)
{
pg_array[des_array.indexOf("gallery")].addChild(gallery);
setup_counter_add();
}
}
C - Bによって呼び出されるギャラリー スプライトを作成するカスタム クラス。本名はclaudeGallery.as
package com.lks
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.events.ScrollEvent;
import flashx.textLayout.events.ScrollEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import com.jumpeye.Events.MCTEEvents;
import com.greensock.TweenLite;
import com.greensock.layout.*;
import com.greensock.easing.*;
import com.greensock.plugins.ColorMatrixFilterPlugin;
import com.greensock.plugins.TweenPlugin;
import com.asual.swfaddress.SWFAddress;
import flash.display.Loader;
import fl.controls.ProgressBar;
import fl.controls.ScrollBar;
import fl.controls.ScrollBarDirection;
TweenPlugin.activate([ColorMatrixFilterPlugin]);
public class claudeGallery extends Sprite
{
public var p3_gallery_loader:URLLoader = new URLLoader ;
public var image_list:XMLList = new XMLList ;
public var number_of_images:Number = new Number ;
public var g_des_array:Array = new Array ;
public var thumb_height:Number = new Number ;
public var thumb_width:Number = new Number ;
public var thumb_space:Number = new Number ;
public var container_mc:Sprite = new Sprite ;
public var container_mask_width:Number = new Number ;
public var x_counter:Number = 0;
public var current_image:Loader;
public var trashed_image:Loader;
public var current_g_scroll:ScrollBar;
public var container_mask:Sprite = new pg_bg_mc ;
public var thumb_array:Array = new Array ;
public var image_area:AutoFitArea;
public var loaded_counter:Number = new Number ;
public var scroll_wh:Number = 15;
public var current:Number = 0;
public var gallery_xml:String;
public var gallery_height:Number;
public var gallery_width:Number;
public var update_allowed:Boolean = false;
public function claudeGallery(xml:String,Width:Number = 400, Height:Number=300,useAddress:Boolean = false,baseURL:String = "gallery",init_array:Array = null)
{
p3_gallery_loader.load(new URLRequest(xml));
p3_gallery_loader.addEventListener(Event.COMPLETE,process_gallery);
gallery_height = Height;
gallery_width = Width;
function process_gallery(e:Event):void
{
var gallery_xml:XML = new XML(e.target.data);
thumb_width = gallery_xml. @ WIDTH;
thumb_height = gallery_xml. @ HEIGHT;
thumb_space = gallery_xml. @ SPACE;
image_list = gallery_xml.IMAGE;
number_of_images = image_list.length();
container_mask_width = gallery_width;
create_container();
}
function create_container():void
{
with (container_mc)
{
y = gallery_height - thumb_height - scroll_wh;
addEventListener(MouseEvent.ROLL_OVER,thumb_over);
addEventListener(MouseEvent.ROLL_OUT,thumb_out);
}
addChild(container_mc);
with (container_mask)
{
width = container_mask_width;
height = thumb_height;
y = container_mc.y;
x = container_mc.x;
}
addChild(container_mask);
container_mc.mask = container_mask;
load_thumbs();
dispatchEvent(new Event("SETUP_COMPLETE",true));
}
function load_thumbs():void
{
for (var i:uint; i < number_of_images; i++)
{
g_des_array[i] = String(image_list[i]. @ DES);
var target_thumb = image_list[i]. @ THUMB;
var thumb_loader = new Loader ;
with (thumb_loader)
{
load(new URLRequest(target_thumb));
contentLoaderInfo.addEventListener(Event.COMPLETE,thumb_loaded);
x = ((thumb_width + thumb_space) * x_counter);
name = i;
}
var preloader_pb:ProgressBar = new ProgressBar ;
with (preloader_pb)
{
x = thumb_loader.x;
y = thumb_loader.y + (thumb_height / 2);
width = thumb_width;
source = thumb_loader.contentLoaderInfo;
addEventListener(Event.COMPLETE,remove_preloader);
}
thumb_array[i] = thumb_loader;
container_mc.addChild(preloader_pb);
x_counter++;
if ((i == number_of_images - 1))
{
if (useAddress==true && init_array!=null)
{
if (init_array[1] != "" && init_array[2] != "" && init_array[1] == baseURL)
{
current = g_des_array.indexOf(init_array[2]);
if ((current == -1))
{
current = 0;
}
SWFAddress.setValue(baseURL + "/" + image_list[current]. @ DES);
}
}
}
}
}
function thumb_loaded(e:Event):void
{
e.target.content.smoothing = true;
var thumb:Loader = Loader(e.target.loader);
with (thumb)
{
alpha = 0;
width = thumb_width;
height = thumb_height;
}
container_mc.addChild(thumb);
TweenLite.to(thumb,0.25,{alpha:1,colorMatrixFilter:{saturation:0}});
loaded_counter++;
dispatchEvent(new Event("THUMB_LOADED",true));
if ((loaded_counter == number_of_images))
{
add_scroll();
}
}
function load_full(e:MouseEvent):void
{
load_full_image(e.target.name);
if (useAddress == true)
{
SWFAddress.setValue(baseURL + "/" + image_list[e.target.name]. @ DES);
}
}
function load_full_image(e:Number):void
{
with (container_mc)
{
removeEventListener(MouseEvent.CLICK,load_full);
removeEventListener(MouseEvent.ROLL_OVER,thumb_over);
removeEventListener(MouseEvent.ROLL_OUT,thumb_out);
}
if ((current_image != null))
{
trashed_image = current_image;
TweenLite.to(trashed_image,0.1,{alpha:0,onComplete:collect_image_trash,onCompleteParams:[true]});
}
var full_loader:Loader = new Loader ;
var target_full = image_list[e]. @ FULL;
if ((target_full != undefined))
{
full_loader.load(new URLRequest(target_full));
full_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,full_loaded);
var full_pb:ProgressBar = new ProgressBar ;
with (full_pb)
{
width = gallery_width;
x = 0;
y = gallery_height / 2 - full_pb.height / 2;
alpha = 0;
source = full_loader.contentLoaderInfo;
addEventListener(Event.COMPLETE,remove_preloader);
}
addChild(full_pb);
TweenLite.to(full_pb,0.1,{alpha:1});
}
else if ((target_full == undefined))
{
with (container_mc)
{
removeEventListener(MouseEvent.CLICK,load_full);
removeEventListener(MouseEvent.ROLL_OVER,thumb_over);
removeEventListener(MouseEvent.ROLL_OUT,thumb_out);
}
}
}
function full_loaded(e:Event):void
{
e.target.content.smoothing = true;
var full:Loader = Loader(e.target.loader);
full.visible = false;
addChild(full);
current_image = full;
updateArea(gallery_width,gallery_height,false);
var pic_in:MCTE = new MCTE(full,true,"show","Stripes",1,100,"Strong","easeOut",75,"","","","","");
pic_in.addEventListener(MCTEEvents.TRANSITION_END,pic_in_end);
with (container_mc)
{
addEventListener(MouseEvent.CLICK,load_full);
addEventListener(MouseEvent.ROLL_OVER,thumb_over);
addEventListener(MouseEvent.ROLL_OUT,thumb_out);
}
dispatchEvent(new Event("FULL_LOADED",true));
function pic_in_end(e:MCTEEvents):void
{
full.mask = null;
}
}
function collect_image_trash(e:Boolean):void
{
removeChild(trashed_image);
if ((e == true))
{
trashed_image = null;
}
}
function remove_preloader(e:Event):void
{
var trashed_pb:ProgressBar = ProgressBar(e.target);
trashed_pb.removeEventListener(Event.COMPLETE,remove_preloader);
try
{
container_mc.removeChild(trashed_pb);
trashed_pb = null;
}
catch (e:Error)
{
removeChild(trashed_pb);
trashed_pb = null;
}
}
function thumb_over(e:MouseEvent):void
{
TweenLite.to(e.target,0.25,{colorMatrixFilter:{saturation:1}});
}
function thumb_out(e:MouseEvent):void
{
TweenLite.to(e.target,0.25,{colorMatrixFilter:{saturation:0}});
}
function add_scroll():void
{
container_mask.height = container_mc.height;
var scroll_g:ScrollBar = new ScrollBar();
with (scroll_g)
{
direction = ScrollBarDirection.HORIZONTAL;
x = container_mc.x;
y = container_mc.y + container_mc.height + thumb_space;
width = container_mask.width;
setScrollProperties(gallery_width,0,container_mc.width - container_mask.width);
lineScrollSize = thumb_width + thumb_space;
addEventListener(ScrollEvent.SCROLL,g_scroll);
visible = false;
}
addChild(scroll_g);
var thumbs_width:Number = (number_of_images * (thumb_width + thumb_space)) - thumb_space;
if ((thumbs_width > container_mask.width))
{
scroll_g.visible = true;
}
else
{
scroll_g.visible = false;
}
current_g_scroll = scroll_g;
dispatchEvent(new Event("ALL_THUMBS_LOADED",true));
container_mc.addEventListener(MouseEvent.CLICK,load_full);
update_allowed = true;
load_full_image(current);
}
function g_scroll(e:ScrollEvent):void
{
TweenLite.to(container_mc,1,{x: - e.position,ease:Strong.easeOut});
}
}
public function updateArea(Width:Number, Height:Number,resetScroll:Boolean = true):void
{
if (update_allowed == true)
{
gallery_height = Height;
gallery_width = Width;
if ((current_image != null))
{
try
{
image_area = new AutoFitArea(current_image.parent,0,0,gallery_width,gallery_height - container_mc.height - thumb_space - scroll_wh);
image_area.attach(current_image);
}
catch (e:Error)
{
}
current_image.visible = true;
}
container_mc.y = gallery_height - thumb_height - scroll_wh;
if (resetScroll == true)
{
current_g_scroll.setScrollPosition(0);
}
container_mask.y = container_mc.y;
container_mask.width = gallery_width;
var thumbs_width:Number = (number_of_images * (thumb_width + thumb_space)) - thumb_space;
if ((thumbs_width > container_mask.width))
{
with (current_g_scroll)
{
visible = true;
width = container_mask.width;
y = container_mc.y + container_mc.height + thumb_space;
setScrollProperties(gallery_width,0,container_mc.width - container_mask.width);
}
}
else
{
current_g_scroll.visible = false;
}
}
}
}
}