Add your Stage in a ScrollWindow ActionScript 3.0

75 Views Asked by At

I'm gonna try explaining my situation with images, to make sure that everyone will understand what i want to succeed.

First of all i have 3 files:

GenImage.fla which is linked to class GeneralImage.as and it only contains the following picture (I tried to make the image Movie Clip but again it's not working):

Pic1

and a file named ScrollUI.as which contains the class ScrollUI.

What i want to succeed is from my GeneralImage class to create a ScrollUi item, pass the stage, and there create a ScrollPane which makes the picture look like this:

Pic2

The center part of the second image is the ScrollPane Component, which i need to make it Scrollable through the whole image. I managed to get it in my screen but i can't put the Stage in it and make it scrollable.

These are my codes :

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);

        }
    }

}

So what i want it to set the Source of the Scroll Pane ( which is named aSp ) to be the _mainStage which is the stage i get from GeneralImage

2

There are 2 best solutions below

1
BadFeelingAboutThis On BEST ANSWER

Your issues is likely these two lines:

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

You're doing a comparison by using two ==, which effectively does nothing in your case. Use a single = to assign a value.

This is how I would suggest you approach this:

In the FlashPro library, find your image asset (I'm going to assume you have it wrapped in a MovieClip), right-click (or command click) and go to it's properties. Check the "export for actionscript" box, and give it a meaningful class name (for my example, I'll assume you called it MyImage)

Then you could do the following:

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;

        }
    }

}

Document 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());
        }

    }

}

You could also just set the .source property of the scroll pane to the physical path of your image.

0
VagPel On

I found the solution, Thanks Batman for his help, I changes some things into my code and the program is working.

First of all as Batman said , In my GenImage.fla i made the logo a MovieClip and i named it "wholemap"

Here are my codes :

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);
        }
    }

}

Thank you very much for your assistance, I hope if someone else come across with this problem to be able to solve it with this Answer