我会尝试用图像解释我的情况,以确保每个人都能理解我想要成功的东西。
首先,我有3个文件:
链接到 GeneralImage.as 的GenImage.fla 它只包含下面的图片(我试图制作图片Movie Clip,但它又不起作用):
以及名为 ScrollUI.as 的文件,其中包含 ScrollUI 类。
我想成功的是从我的GeneralImage类创建一个ScrollUi项目,传递舞台,然后创建一个ScrollPane,使图片看起来像这样:
第二个图像的中心部分是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获得的阶段
答案 0 :(得分:0)
你的问题很可能是这两行:
aBox == stage as MovieClip;
aSp.source == aBox ;
您正在使用两个==
进行比较,这在您的情况下实际上无效。使用单个=
分配值。
我建议你这样做:
在FlashPro库中,找到您的图像资源(我假设您将其包装在MovieClip中),右键单击(或命令单击)并转到它的属性。检查" 导出动作脚本"框,并给它一个有意义的类名(我的例子,我假设你称之为 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;
}
}
}
文档类
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
属性设置为图像的物理路径。
答案 1 :(得分:0)
我找到了解决方案,感谢蝙蝠侠的帮助,我将一些内容更改为我的代码,程序正在运行。
首先,蝙蝠侠说,在我的 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);
}
}
}
非常感谢你的帮助,我希望如果有人遇到这个问题,能用这个问题来解决它