0

设置

我有两个 SWF,ABAB的简单预加载器,它作为子项添加到AB使用我编写的自定义类来创建照片库,我将其称为C。这是我第一次尝试自己上课,所以请多多包涵:/

问题

当我测试A时,我收到此错误:

ReferenceError: Error #1065: Variable ScrollEvent is not defined.
    at MethodInfo-4757()
    at MethodInfo-4748()

现在有几个原因导致这特别令人困惑。首先,在C中定义(后面的代码)ScrollEvent。其次,B在库中有一个UIScrollBarand ProgressBarC也使用的东西)组件,但是当我将一个ScrollBarandProgressBar组件添加到A的库时,错误消失了,但是生成的 SWF 使用的是A中的组件,而不是自定义蒙皮的组件。这可能有一个明显的答案,但我对这个很困惑,所以任何帮助都将不胜感激!

B - 由A加载的主 SWF,用于创建C的实例。该项目被称为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;
                }
            }
        }
    }

}
4

1 回答 1

0

Since C is just an *.as file it is actually compiled into a B's swf when project B references it and is built. If A has not loaded B then it has no reference to C. This is why you see that behavior with the error vs no error.

Insofar as class loading is concerned, where you see that the classes from A are being used over the classes in B you may want to consider just renaming your classes in B to avoid the conflict (if they have a different package and you import you should also be able to avoid this issue). Alternatively I believe you can explicitly get the class from the swf:

AS3 Instantiate Class From External SWF

Also in your title you say "parent" swf. Generally anything you load where it's like A loads B you would say "B is a dependency of A", or "A depends on B", the whole parent/child thing is generally used to describe relationships in the visual hierarchy or data hierarchy.

于 2013-06-14T17:47:15.480 回答