Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash AS3缩放-剪切文本并扭曲照片上的对角线_Flash_Actionscript 3_Scaling_Movieclip_Moviecliploader - Fatal编程技术网

Flash AS3缩放-剪切文本并扭曲照片上的对角线

Flash AS3缩放-剪切文本并扭曲照片上的对角线,flash,actionscript-3,scaling,movieclip,moviecliploader,Flash,Actionscript 3,Scaling,Movieclip,Moviecliploader,嗨,我用了一些我发现的代码,我想即使是你们这些家伙,也可以将外部swf加载到背景电影剪辑中。除了剪辑一些文本、创建一些有趣的斜线和一些较差的图片质量外,效果非常好。 我有一种感觉,这是由于一些地方的尺寸略有不同。 舞台尺寸是2560 x 1440,可以缩小到任何尺寸,但正如我提到的,我认为对于宽屏格式来说,高度和宽度并不完全同步。请帮帮我,它正在把我的头伸进去 请看一看,我对AS3不是很在行 www.sirwin.co.uk // perform initial size check chec

嗨,我用了一些我发现的代码,我想即使是你们这些家伙,也可以将外部swf加载到背景电影剪辑中。除了剪辑一些文本、创建一些有趣的斜线和一些较差的图片质量外,效果非常好。 我有一种感觉,这是由于一些地方的尺寸略有不同。 舞台尺寸是2560 x 1440,可以缩小到任何尺寸,但正如我提到的,我认为对于宽屏格式来说,高度和宽度并不完全同步。请帮帮我,它正在把我的头伸进去

请看一看,我对AS3不是很在行

www.sirwin.co.uk

// perform initial size check

checkStageSize();

// register to re-check when stage size changes
stage.addEventListener( Event.RESIZE, onResize, false, 0, true );

function onResize( e:Event ) {

    checkStageSize();
}

// do the scaling here

function checkStageSize():void {

    var wid:Number = stage.stageWidth;

    var hi:Number = stage.stageHeight;

    var needToScaleDown:Boolean = (wid < 0); // or some other test

    if ( needToScaleDown ) {

        var scale:Number = wid/0;

        backgroundRectangle.scaleX = backgroundRectangle.scaleY = scale;

    } else {

        backgroundRectangle.scaleX = backgroundRectangle.scaleY = 1;
    }
}

stop();
var portRequest:URLRequest = new URLRequest("main.swf");

var portLoader:Loader = new Loader();

 portLoader.load(portRequest);
 backgroundRectangle.addChild(portLoader);
//执行初始大小检查
checkStageSize();
//注册以在阶段大小更改时重新检查
stage.addEventListener(Event.RESIZE、onResize、false、0、true);
函数onResize(e:事件){
checkStageSize();
}
//在这里进行缩放
函数checkStageSize():void{
var wid:Number=stage.stageWidth;
var hi:数值=阶段高度;
var needToScaleDown:Boolean=(wid<0);//或其他一些测试
如果(需要缩减){
变量范围:数值=wid/0;
backgroundRectangle.scaleX=backgroundRectangle.scaleY=比例;
}否则{
backgroundRectangle.scaleX=backgroundRectangle.scaleY=1;
}
}
停止();
var-portRequest:URLRequest=newurlrequest(“main.swf”);
var portLoader:Loader=new Loader();
加载(portRequest);
backgroundRectangle.addChild(portLoader);

您的代码似乎存在一些问题。一个是技术性的,另一个是基础性的。让我们先看看基本面

我不得不对你的文件进行反编译,以查看你所有的代码到底是什么样子(在本例中-)这个文件是1.9 mb,对于包含一些照片的flash文件来说,这个文件非常大。更好的方法是将这些图像放在外部文件夹中,并根据需要动态加载它们。这有很多好处:

  • 易于更新-无需重新编译闪存文件
  • xml或php驱动(对于那些不喜欢使用xml的人,甚至可以使用php根据目录中的文件夹结构生成结构)
  • 当你在代码/oop部门变得更具冒险精神时,你甚至可以看看Hydroticks队列加载器类,用于在zip文件夹中加载-
  • 您甚至可以使用flickr flash api的一个应用程序从您的flickr帐户请求集并动态加载(我喜欢这种方法,因为它允许您将flickr用作各种内容管理系统)
我不确定你的技能水平,所以让我们先解决技术问题。 忽略图像太大这一点-您需要确保通过库或某些代码启用平滑。最简单但劳动密集的方法是在库中的图像上双击clikc并选中“允许平滑”以启用。虽然有这么大的图像,但即使打开它,也可能会有一些锯齿

第二种方法涉及编写脚本,在帧更改时从movieclip中提取位图数据,删除其内容,并将其重新绘制到平滑属性设置为true的容器中

至于实现这一点的代码,您用于为每个部分生成照片数组的方法会有很大的不同,但代码的核心可以在这里找到:

但是真的,如果你沿着这条路走,你最好走整整9码

一便士换一英镑
希望这有帮助

感谢Beans,我将进一步探讨画廊的更好方式,我希望在SWF中使用图像的主要原因是当我完成设计并更改任何问题时,我无法锁定和密码保护,因此图像被盗的可能性较小

然而,我在图像上有了更大的改进,尽管文本(主要是按钮)上的剪辑比以往任何时候都让我恼火

我改成的代码是:

stage.addEventListener(Event.RESIZE, resizeListener);
stage.scaleMode=StageScaleMode.SHOW_ALL;
stage.align=StageAlign.TOP_LEFT;

function resizeListener(e:Event):void {
    trace("stageWidth: " + stage.stageWidth + " stageHeight: " + stage.stageHeight);


    // do the scaling here

    var wid:Number=100/this.stage.stageWidth;
    var hi:Number=100/this.stage.stageHeight;
    this.stage.scaleX=this.stage.scaleY;
    this.stage.scaleX=this.stage.scaleY;

    this.stage.x = (100 - this.stage.width) * 0;
    this.stage.x = (100 - this.stage.height) * 0;
}

出于许多原因,使用.SWF打包文件并不理想,但我没有考虑安全方面。虽然当然-如果它在网上,它是不安全的

今天早上我为大家准备了一个小演示,可以在这里找到:

演示:

下载:

让我解释几个特点:

  • 它使用hydrotik的queueLoader类。它使加载和监视变得轻而易举
  • 所有资产均为编制的主权财富基金。队列加载的一个重要特性是将SWF的帧绘制为位图数据(非常适合平滑处理)
  • 它使用“调整大小”事件来确保将图像调整为缩放大小
  • swf中的所有图像都是720p大小(1024x720),因此您可以很好地了解大图像如何缩放更小(在24-27英寸屏幕上缩放更大)
调整侦听器的大小:

            stage.scaleMode = StageScaleMode.NO_SCALE;      // the standard top left align, add some no scaling and throw in the event listener
            stage.align = StageAlign.TOP_LEFT;
            stage.addEventListener(Event.RESIZE, resizePhoto, false, 0, true);   
调整大小功能:(我们在加载图像时存储一次photoWidth和photoHeight变量,这样我们就不必检查每一帧)

函数大小照片(e:事件){
var targetWidth=stage.stageWidth-buffer-photo.x
//这给了我们想要照片的目标宽度。我们可以计算出制作这张照片所需的图像的百分比,并将其用作比例倍增。。
var targetHeight=stage.stageHeight-buffer-photo.y
//这给了我们想要照片的目标高度。我们可以计算出制作这张照片所需的百分比,并将其用作比例倍增。。
//注意:在此基础上添加一些智能大小调整-这意味着照片大小调整在达到高度或宽度限制时停止。。
变量wMult:Number=(targetWidth/photoWidth)
变量hMult:Number=(目标光/照片高度)
如果(wMult        function resizePhoto(e:Event){

            var targetWidth = stage.stageWidth - buffer - photo.x       
            // this gives us the target width we want the photo. we can figure out what percent the image would need to be to make this, and use that as a scale mutiplication..

            var targetHeight = stage.stageHeight - buffer - photo.y     
            // this gives us the target height we want the photo. we can figure out what percent the image would need to be to make this, and use that as a scale mutiplication..               

            //note: add in some smart sizing on this - this means the photo resize stops when it hits a height or width limit..                             
            var wMult:Number = (targetWidth / photoWidth)   
            var hMult:Number = (targetHeight / photoHeight)

            if(wMult < hMult){
                photo.width =  photoWidth * wMult   
                photo.height = photoHeight * wMult
            }else{
                photo.width =  photoWidth * hMult   
                photo.height = photoHeight * hMult
            }
        }
package{

    import flash.ui.*;
    import flash.display.*;
    import flash.events.*;  
    import flash.text.*;
    import flash.geom.*;
    import flash.net.*; 
    import flash.utils.*;
    import flash.media.*

    import fl.controls.Button;

    import com.hydrotik.queueloader.QueueLoader;
    import com.hydrotik.queueloader.QueueLoaderEvent;
    import com.hydrotik.queueloader.QLManager;  


    public class Sirwin extends MovieClip { 

        var sec_PERSONAL:Array = ['Animals', 'Macro'];  // all of the topic sections... Note, the swf files need to match these names!          
        var sec_LENGTH:uint = 0;    // the length of the loaded array
        var sec_CUR:uint = 0;       // the length of the loaded array
        var bmp_ARRAY:Array = [];   // the container for the loaded section
        var buffer:uint = 10;       // buffer in pixels for button placement

        var _oLoader:QueueLoader = new QueueLoader();
        var photo:Sprite = new Sprite();        // holder for the photo to load into

        var nextBut:Button = new Button();      // attach the next button from the library
        var prevBut:Button = new Button();      // attach the prev button from the library

        var photoWidth:Number   // we store these as variables to improve performance, check once - not each time
        var photoHeight:Number  // we store these as variables to improve performance, check once - not each time


        public function Sirwin(){
            trace("initialising Document...");
            addEventListener(Event.ADDED_TO_STAGE, popStageVars);   // once the movie has been added to the stage, we can set up some more vars 
        }

        private function popStageVars(e:Event){
            trace("popping stage vars...")  
            removeEventListener(Event.ADDED_TO_STAGE, popStageVars);

            stage.scaleMode = StageScaleMode.NO_SCALE;      // the standard top left align, add some no scaling and throw in the event listener
            stage.align = StageAlign.TOP_LEFT;
            stage.addEventListener(Event.RESIZE, resizePhoto, false, 0, true);   

            _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true);
            _oLoader.addEventListener(QueueLoaderEvent.ITEM_PROGRESS, onQueueProgress, false, 0, true);
            _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true);                 

            photo.x = 180
            photo.y = buffer
            addChild(photo)

            setSections();
            setNav();
            toggleNav();                
        }


        function resizePhoto(e:Event){

            // set photo dimensions to match stage;
            photo.width = stage.stageWidth - buffer;
            photo.height = stage.stageHeight - buffer;

            // choose the larger scale property and match the other to it;
            ( photo.scaleX < photo.scaleY ) ? photo.scaleY = photo.scaleX : photo.scaleX = photo.scaleY;




        }


        public function setSections(){  // this function places the section buttons on the stage... not so neccesary if you make your own buttons

            for(var i:uint = 0; i < sec_PERSONAL.length; i++){  
                var but:Button = new Button();  // attach the button from the library
                but.label = sec_PERSONAL[i]     // give the button a label from the array of names
                but.x = buffer
                but.y = buffer*5 + (i * (buffer + but.height));                 
                but.addEventListener(MouseEvent.CLICK, loadSection, false, 0, true);    // weak handler for better garbage collection
                addChild(but)
            }
        }

        public function setNav(){   // this function places the nav buttons on the stage... better practice would be having their own class and dispatching mouse events to be listened for. Baby steps..
            nextBut.label = "Next >"
            nextBut.x = buffer
            nextBut.y = 350
            nextBut.addEventListener(MouseEvent.CLICK, navForward, false, 0, true);
            addChild(nextBut)               

            prevBut.label = "Previous <"
            prevBut.x = buffer
            prevBut.y = 400
            prevBut.addEventListener(MouseEvent.CLICK, navBack, false, 0, true);
            addChild(prevBut)
        }


        public function loadSection(e:MouseEvent){
            bmp_ARRAY = []; // reset the array to nothing
            var swf:String = convertFolderName(e.target.label, '_') + ".swf";   
            _oLoader.addItem("assets/"+swf, null, {title:"SWF Images", drawFrames:true});
            _oLoader.execute();                         
        }       

        public function loadPhoto(){
            while(photo.numChildren){
                    photo.removeChildAt(0);     // get rid of any existing photo
            }

            var bmp:Bitmap = new Bitmap(bmp_ARRAY[sec_CUR]);        // this gets the bitmap data from the array that has been loaded from the zip file
            bmp.smoothing = true;   // this should solve your smoothing issues
            photo.addChild(bmp);

            photoWidth = photo.width;   // update the photos height and width for easy ref              
            photoHeight = photo.height;
            resizePhoto(null);      // pass through a null event to avoid any compiler errors
        }


        public function convertFolderName(s:String, replacement:String):String{ // this function returns an underscore instead of a space                           
            var trimmedValue:String = s.replace(" ", replacement)
            return trimmedValue;
        }   


        public function updateCur(n:Number){                        
            sec_CUR += n;       // add a +1, or -1 to the current pointer
            displaying.text = "Displaying: " + (sec_CUR + 1) + "/" + sec_LENGTH;        // this updates the 'number of/how many' text. you need plus one to adjust for arrays starting at 0
        }

        public function navForward(e:MouseEvent){
            updateCur(1)
            toggleNav();
            loadPhoto();
        }

        public function navBack(e:MouseEvent){
            updateCur(-1)
            toggleNav();
            loadPhoto() 
        }


        public function toggleNav():void{   //this function decides if the next or back should be shown
            trace(sec_CUR + " - " + sec_LENGTH)
            nextBut.visible = (sec_CUR >= sec_LENGTH-1) ? false : true
            prevBut.visible = (sec_CUR <= 0) ? false : true

            if(sec_CUR < 0){
                sec_CUR = 0;    
            }

            if(sec_CUR >= sec_LENGTH-1){
                sec_CUR = sec_LENGTH-1; 
            }
        }

        // ----------------------------------------------------- queue loading event handlers


        public function onQueueProgress(event:QueueLoaderEvent):void {  // cheap preloading...
            trace("\t>>onQueueProgress: "+event.queuepercentage);
            displaying.text = "Loading: " + event.queuepercentage + "%";
        }

        public function onItemComplete(event:QueueLoaderEvent):void {
            trace("\t>> "+event.type, "item title: "+event.title + " type: " + event.fileType);
            if (event.title == "SWF Images") {
                bmp_ARRAY = [];
                for (var i:int = 0; i<event.bmArray.length; i++) {
                    var bm:BitmapData = event.bmArray[i]                
                    bmp_ARRAY.push(bm)
                }
            }
        }

        public function onQueueComplete(event:QueueLoaderEvent):void {
            trace("** "+event.type);

            sec_LENGTH = bmp_ARRAY.length
            sec_CUR = 0;

            updateCur(0)
            toggleNav();
            loadPhoto();                                            
        }               


    }       
}