在 ScrollWindow ActionScript 3.0 中添加您的舞台

Add your Stage in a ScrollWindow ActionScript 3.0

我会尝试用图片来解释我的情况,以确保每个人都能理解我想要成功的原因。

首先我有 3 个文件:

GenImage.fla 链接到 class GeneralImage.as 并且它只包含以下图片(我试图制作图像 Movie Clip 但它再次不起作用):

Pic1

和一个名为 ScrollUI.as 的文件,其中包含 class ScrollUI.

我想要成功的是从我的 GeneralImage class 创建一个 ScrollUi 项目,通过舞台,然后创建一个 ScrollPane 使图片看起来像这样:

Pic2

第二张图片的中间部分是 ScrollPane 组件,我需要让它在整个图片中滚动。我设法将它显示在我的屏幕上,但我无法将舞台放入其中并使其可滚动。

这些是我的代码:

GeneralImage.as

package  {

    import flash.display.*;
    import flash.events.*;
    import flash.display.Stage;
    import ScrollUI;


    public class GeneralImage extends MovieClip
    {

        public function GeneralImage()
        {
            var k = new ScrollUI();
            k.ScrollConstructor(this);

        }

    }

}

ScrollUI.as

package  
{

    import flash.display.*;
    import flash.events.*;
    import fl.containers.ScrollPane; 
    import fl.events.ScrollEvent;
    import fl.controls.ScrollPolicy; 

    public class ScrollUI extends MovieClip
    {
        private var _mainStage:Stage;
        var aBox:MovieClip = new MovieClip(); 
        var aSp:ScrollPane = new ScrollPane();

        public function ScrollUI()
        {
        }

        function ScrollConstructor(stage:Object):void
        {
            _mainStage = (stage as MovieClip).stage;
            aBox == stage as MovieClip;
            aSp.source == aBox ;
            _mainStage.addChild(aBox);
            aSp.setSize(300,300);
            aSp.move(150, 75); 
            aSp.scrollDrag = true;
            aSp.horizontalScrollPolicy=ScrollPolicy.OFF;
            _mainStage.addChild(aSp);

        }
    }

}

所以我希望它将滚动窗格的来源(名为 aSp)设置为 _mainStage,这是我从 GeneralImage

获得的阶段

您的问题可能是这两行:

 aBox == stage as MovieClip;
 aSp.source == aBox ;

您正在使用两个 == 进行比较,这对您的情况没有任何效果。使用单个 = 赋值。

我建议您采用以下方法:

在 FlashPro 库中,找到您的图像资源(我假设您已将其包装在 MovieClip 中),右键单击(或命令单击)并转到其属性。选中“export for actionscript”框,并为其指定一个有意义的 class 名称(对于我的示例,我假设您将其命名为 MyImage)

那么您可以进行以下操作:

ScrollUI Class

package  
{

    import flash.display.Sprite;
    import fl.containers.ScrollPane; 
    import fl.events.ScrollEvent;
    import fl.controls.ScrollPolicy; 

    public class ScrollUI extends Sprite
    {
        //just declare the variables here, don't assign them new values
        private var aBox:MovieClip; 
        private var aSp:ScrollPane;

        public function ScrollUI()
        {
            //use the actual constructor...

            aSp = new ScrollPane(); //instantiate a new scroll pane
            addChild(aSp); //add the scroll pane to the display

            aBox = new MyImage(); //instantiate an new MyImage from the library
            //set the scroll pane properties
            aSp.source = aBox; //you had two = signs here before, which doesn't actually assign anything it compares
            aSp.setSize(300,300);
            aSp.move(150, 75); 
            aSp.scrollDrag = true;
            aSp.horizontalScrollPolicy=ScrollPolicy.OFF;

        }
    }

}

文档Class

package  {

    import ScrollUI;


    public class GeneralImage extends MovieClip
    {

        public function GeneralImage()
        {
            var k:ScrollUI = new ScrollUI(); //create a new instance of the ScrollUI class
            addChild(k); //add the scrollUI object to the display;

            //OR, you just do this:
            //addChild(new ScrollUI());
        }

    }

}

您也可以将滚动窗格的 .source 属性 设置为图像的物理路径。

我找到了解决方案,感谢蝙蝠侠的帮助,我更改了一些代码到我的代码中,程序运行正常。

首先,正如蝙蝠侠所说,在我的 GenImage.fla 中,我将徽标制作为 MovieClip,并将其命名为 "wholemap"

这是我的代码:

GeneralImage.as

package  {

    import flash.display.*;
    import flash.events.*;
    import flash.display.Stage;
    import ScrollUI;

    public class GeneralImage extends MovieClip
    {
//as Batman indicated, I should have used the ScrollUI constructor, but 
//except for the Stage, i also send the wholemap that is in my GenImage.fla
//<< this.getChildByName("wholemap") as MovieClip) >>
        public function GeneralImage()
        {
            var k = new ScrollUI(this, this.getChildByName("wholemap") as MovieClip); 
        }
    }

}

ScrollUI.as

package  
{
    import flash.display.*;
    import flash.events.*;
    import fl.containers.ScrollPane; 
    import fl.events.ScrollEvent;
    import fl.controls.ScrollPolicy; 

    public class ScrollUI extends MovieClip
    {
        private var _mainStage:Stage;
        var aBox:MovieClip = new MovieClip(); 
    //So our constructor gets 2 items, a Stage, and a MovieClip
        public function ScrollUI(stage:Object, pic:MovieClip)
        {
    //We set the Stage at the variable _mainStage with that way:
            _mainStage = (stage as MovieClip).stage;
    //We set the Image that we will take at our clip variable :
            var clip:MovieClip = pic;
    //And we send the Movieclip (clip) in our ScrollConstructor function
            ScrollConstructor(clip);
        }

        function ScrollConstructor(Clip:MovieClip):void
        {
            var aSp:ScrollPane = new ScrollPane();
            aBox = Clip;
            _mainStage.addChild(aBox);
            aSp.source = aBox ;
            aSp.setSize(300,300);
            aSp.move(150, 75); 
            aSp.scrollDrag = true;
            aSp.horizontalScrollPolicy=ScrollPolicy.OFF;
            aSp.verticalScrollPolicy=ScrollPolicy.OFF;
            _mainStage.addChild(aSp);
        }
    }

}

非常感谢您的帮助,我希望如果其他人遇到这个问题能够用这个答案解决它