Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   Zoom с помощью transitions (http://www.flasher.ru/forum/showthread.php?t=124068)

DrugON 20.04.2009 16:19

Zoom с помощью transitions
 
Код AS3:

function loaderCompleteHandler(evt:Event):void {
        var vars:URLVariables = new URLVariables();
        vars.decode(evt.currentTarget.data);
        pictures = new Array();
        transitions = new Array();
        for (var i:int = 0; i < vars.Totalnumber_of_entries; i++) {
                try {
                        var picture:Picture = new Picture(vars["foto_url" + i]);
                        addChild(picture);
                        pictures.push(picture);
                        picture.posX = 100;
                        picture.posY = 100;
                        picture.addEventListener(MouseEvent.MOUSE_OVER, mouseOverBox);
                } catch (err:Error) {
                        trace("BAD");
                }
        }
}
 
function mouseOverBox(evt:Event):void {
        var selectedBox:MovieClip = MovieClip(evt.target);
        selectedBox.removeEventListener(MouseEvent.MOUSE_OVER, mouseOverBox);
        var myTransitionManager:TransitionManager = new TransitionManager(selectedBox);
        myTransitionManager.startTransition({type:Zoom, direction:Transition.IN, duration:1, easing:Regular.easeOut, shape:Iris.CIRCLE});
        transitions.push(myTransitionManager);
        myTransitionManager.addEventListener("allTransitionsInDone", animationComplete);
}
 
function animationComplete(evt:Event):void {
        evt.target.content.addEventListener(MouseEvent.MOUSE_OVER, mouseOverBox);
}

Не получается сделать zoom для картинок. При наведении на картинки пишет ошибку
Код:

TypeError: Error #1034: Type Coercion failed: cannot convert Picture@10e2cd29 to flash.display.MovieClip.
        at index_fla::MainTimeline/mouseOverBox()

Помогите разобраться.

CrazyFlasher 20.04.2009 16:28

попробуйте так...а еще лучше покажите класс Picture
Код AS3:

var selectedBox:Picture = evt.target as Picture;

хотя если Picture экстендит MovieClip, то проблемы не должно быть

cihexe 20.04.2009 16:29

сравни это :

Код AS3:

                                  var picture:Picture = new Picture(vars["foto_url" + i]);
                        addChild(picture);
                        pictures.push(picture);
                        picture.posX = 100;
                        picture.posY = 100;
                        picture.addEventListener(MouseEvent.MOUSE_OVER, mouseOverBox);

и это:

Код AS3:

var selectedBox:MovieClip = MovieClip(evt.target);

попробуй подставить:

Код AS3:

var selectedBox:Picture = Picture(evt.target);


DrugON 20.04.2009 16:34

вот класс Picture
Код AS3:

package {
        import flash.display.Sprite;
        import flash.display.Loader;
        import flash.net.URLRequest;
        import flash.events.*;
        import flash.display.Bitmap;
        public class Picture extends Sprite {
                public var posX:Number;
                public var posY:Number;
                public function Picture(url:String):void {
                        var urlRequest:URLRequest = new URLRequest(url);
                        var loader:Loader = new Loader();
                        loader.load(urlRequest);
                        loader.contentLoaderInfo.addEventListener(Event.INIT, initListener);
                }
                private function initListener(event:Event):void {
                        var bmp:Bitmap = event.target.content;
                        bmp.x = -bmp.width/2;
                        bmp.y = -bmp.height/2;
                        addChild(bmp);
                }
        }
}

cihexe исправил как вы сказали получил ошибку
Код:

1067: Implicit coercion of a value of type Picture to an unrelated type flash.display:MovieClip.

CrazyFlasher 20.04.2009 16:37

Код AS3:

public class Picture extends Sprite {

ну правильно делает, что кидает ошибку.

делайте так
Код AS3:

var selectedBox:Picture = evt.target as Picture;

или так
Код AS3:

var selectedBox:Sprite = evt.target as Sprite;


DrugON 20.04.2009 16:46

CrazyFlasher в первом варианте выдает ошибку
Код:

1067: Implicit coercion of a value of type Picture to an unrelated type flash.display:MovieClip.
а во втором
Код:

1118: Implicit coercion of a value with static type flash.display:Sprite to a possibly unrelated type flash.display:MovieClip.

cihexe 20.04.2009 16:55

тебе проще зайти в дебаггер, и поставить брейпоинт на
Код AS3:

var selectedBox:MovieClip = MovieClip(evt.target);

и посмотреть что именно приходит в
Код AS3:

evt.target

(просто добавь в watches)

Добавлено через 1 минуту
а лучше проверь
Код AS3:

evt.currentTarget

если у тебя MouseEvent

DrugON 20.04.2009 17:33

Ни чего не приходило.
Просто в классе поменял Sprite на MovieClip. Сейчас ошибку не пишет.

cleptoman 20.04.2009 19:14

var bmp:Bitmap = event.target.loader.content as Bitmap;

DrugON 21.04.2009 15:02

cleptoman, спасибо! Работает, как хотелось!


Часовой пояс GMT +4, время: 20:42.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.