1

我想出了如何加载外部图像并缩放和平移它。(主图)

我想在主图像的某些地方实现信息图标,但是由于图像可以缩放和平移,我需要这些图标保持在原来的位置。

请参阅下图以获得更好的理解。无论图标在哪里,都是产品,如果单击图标,则会加载带有产品信息的外部 .SWF。在完美的世界中,图标不会缩放,只会平移。

我的基本理解是每个图标都必须是一个单独的电影剪辑。每个都有自己的一组听众。当主图像被平移和缩放时,我只是不知道如何使图标留在相关产品上。

任何帮助或建议将不胜感激。

http://www.marketingfanatics.co.za/images/example.jpg

package  {

import flash.display.MovieClip;
import fl.motion.MatrixTransformer;
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.events.KeyboardEvent;
import flash.ui.Mouse;

public class Main extends MovieClip {


    public function Main() {

        mcIn.visible = false;
        mcOut.visible = false;
        infoBox.wordWrap = true;
        infoBox.mouseEnabled = false;

        var board:Sprite = new Sprite();
        addChild(board);

        var boardWidth:int = 690;
        var boardHeight:int = 489;

        board.x = 0.0;
        board.y = 0.0;


        board.graphics.beginFill(0xDDDDDD);
        board.graphics.drawRect(0, 0, boardWidth, boardHeight);
        board.graphics.endFill();

        var spImage:Sprite = new Sprite();
        board.addChild(spImage);

        var boardMask:Shape = new Shape();
        boardMask.graphics.beginFill(0xDDDDDD);
        boardMask.graphics.drawRect(0, 0, boardWidth, boardHeight);
        boardMask.graphics.endFill();
        board.addChild(boardMask);
        spImage.mask = boardMask;

        var scaleFactor:Number = 0.8;
        var minScale:Number = 0.25;
        var maxScale:Number = 2.0;
        var image:Bitmap;

        var loader:Loader = new Loader();
        loader.load(new URLRequest("source_material/Irrigation_1195X847.jpg"));
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, initPic);
        loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, updateInfo);
        infoBox.text = "Loading the Image";

        function updateInfo(e:ProgressEvent):void {
            infoBox.text = "Loading: " + String(Math.floor(e.bytesLoaded/1024)) + " KB of " + String(Math.floor(e.bytesTotal/1024)) + " KB.";
        }

        function initPic(e:Event):void {
            infoBox.text = "";
            infoBox.visible = false;
            image = Bitmap(loader.content);
            minScale = boardWidth/image.width;
            image.scaleX = minScale;
            image.scaleY = minScale;

            spImage.addChild(image);
            spImage.addChild(mcIn);
            spImage.addChild(mcOut);

            spImage.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
            stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);

            loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, initPic);
            loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, updateInfo);
            loader = null;

            board.filters = [ new DropShadowFilter() ];
            spImage.addEventListener(MouseEvent.CLICK, zoom);
        }

        function startDragging(mev:MouseEvent):void {
            spImage.startDrag();
        }

        function stopDragging(mev:MouseEvent):void {
            spImage.stopDrag();
        }

        function zoom(mev:MouseEvent):void {
            if ((!mev.shiftKey) && (!mev.ctrlKey)) {
                return;
            }

            if ((mev.shiftKey) && (mev.ctrlKey)) {
                return;
            }

            var mat:Matrix;

            var externalCenter:Point = new Point(spImage.mouseX, spImage.mouseY);
            var internalCenter:Point = new Point(image.mouseX, image.mouseY);

            if (mev.shiftKey) {
                image.scaleX = Math.max(scaleFactor * image.scaleX, minScale);
                image.scaleY = Math.max(scaleFactor * image.scaleY, minScale);

            }

            if (mev.ctrlKey) {
                image.scaleX = Math.min(1 / scaleFactor * image.scaleX, maxScale);
                image.scaleY = Math.min(1 / scaleFactor * image.scaleY, maxScale);

            }

            mat = image.transform.matrix.clone();

            MatrixTransformer.matchInternalPointWithExternal(mat, internalCenter, externalCenter);

            image.transform.matrix = mat;
        }

        stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
        stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);

        function keyHandler(ke:KeyboardEvent):void {
            mcIn.x = spImage.mouseX;
            mcIn.y = spImage.mouseY;

            mcOut.x = spImage.mouseX;
            mcOut.y = spImage.mouseY;

            mcIn.visible = ke.ctrlKey;
            mcOut.visible = ke.shiftKey;

            if (ke.ctrlKey || ke.shiftKey) {
                Mouse.hide(); } else {
                    Mouse.show();
            }
        }
    }
}

}

4

2 回答 2

0

您的问题:是否可以在 Actionscript 3 中缩放和平移多个图像/影片?

您可以平移该大小的图像,或缩放...由于图像的大小,您会丢失帧,所以我建议使用绿色袜子 BlitMask,完全符合您的需要。它有关于如何使用它的示例:

    http://www.greensock.com/blitmask/

此外,如果您希望滚动多个图像,请将图像放入容器中,因此,movieClip 然后滚动movieclip 或更改比例,更改深度 Z 位置或您所拥有的。

于 2013-04-17T14:21:41.300 回答
0

Sprite在让我们说对象的主图像顶部添加描述。将主图像添加到舞台后,请执行以下操作:setChildIndex(descriptionObject,numChildren-1);这将确保描述位于一切之上。

于 2013-04-17T11:35:43.707 回答