Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   Away3D (http://www.flasher.ru/forum/showthread.php?t=197942)

Shutdown 15.04.2013 21:01

Away3D
 
Доброго времени суток! Недавно начал разбираться с движком away. Весь день сижу уже, не могу разобраться.

Вот код:

Код AS3:

package ro.fwd.thumbwall3d
{       
        import away3d.events.MouseEvent3D;
        import away3d.materials.MovieMaterial;
        import away3d.primitives.Plane;
 
        import flash.display.Bitmap;
        import flash.display.GradientType;
        import flash.display.Loader;
        import flash.display.LoaderInfo;
        import flash.display.Shape;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.EventDispatcher;
        import flash.events.IOErrorEvent;
        import flash.events.MouseEvent;
        import flash.geom.Matrix;
        import flash.net.URLRequest;
        import flash.text.Font;
        import flash.text.StyleSheet;
        import flash.text.TextField;
        import flash.text.TextFieldAutoSize;
        import flash.text.TextFormat;
 
        import gs.TweenMax;
        import gs.easing.Expo;
 
        import ro.fwd.thumbwall3d.events.DataEvent;
        import ro.fwd.thumbwall3d.events.ThumbEvent;
 
        public class Thumb extends EventDispatcher
        {
                private var _id:int;
                private var _imageWidth:Number;
                private var _imageHeight:Number;
                private var _data:Data;
                private var _holder:Plane;
                private var _imageMaterial:MovieMaterial;
                private var _textMaterial:MovieMaterial;
                private var _borderSize:Number;
                private var _imageBorder:Shape;
                private var _textBorder:Shape;
                private var _borderColor:uint;
                private var _flipBtn1:FlipButton;
                private var _flipBtn2:FlipButton;
                private var _textBackround:Shape;
                private var _imageText:TextField;
                private var _flipped:Boolean;
                private var _selected:Boolean;
                private var _textFont:String;
                private var _textSize:Number;
                private var _textColor:uint;
                private var _titleColor:uint;
                private var _textBgColor:uint;
                private var _over:_Over;
                private var over_:Sprite;
                private var _flipBtnColor:uint;
                private var _title:TextField;
                private var _bmp:Bitmap;
                private var _face:Sprite;
                private var _back:Sprite;
                private var _loader:Loader;
 
                public function Thumb(pId:int, pData:Data)
                {
                        _id = pId;
                        _data = pData;
 
                        setProperties();
                        createThumb();
                }
 
                private function setProperties():void
                {
                        _borderSize = _data.borderSize;
                        _borderColor = _data.borderColor;
                        _textSize = _data.textSize;
                        _textFont = _data.textFont;
                        _textColor = _data.textColor;
                        _titleColor = _data.titleColor;
                        _textBgColor = _data.textBackgroundColor;
                        _flipBtnColor = _data.flipButtonColor;
 
                        _flipped = false;
                        _selected = false;
 
                        _holder = new Plane();
                        _holder.yUp = false;
                        _holder.useHandCursor = true;
                        _holder.bothsides = true;
                        _holder.width = _data.thumbSize;
                        _holder.height = _data.thumbSize;
                        _holder.ownCanvas = true;
                }
 
                private function createThumb():void
                {
                        _loader = new Loader();
 
                        _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, setThumb);
                        _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onImageError);
 
                        _loader.load(new URLRequest(_data.imageData[_id].imagePath));
                }
 
                private function setThumb(ev:Event):void
                {
                        var info:LoaderInfo = ev.currentTarget as LoaderInfo;
 
                        _bmp = Bitmap(info.loader.content);
 
                        var w:Number = _bmp.width;
                        var h:Number = _bmp.height;
 
                        var txtH:Number;
 
                        if (w > h)
                                txtH = w * 0.15;
                        else
                                txtH = h * 0.15;
 
                        if (_data.showTitle)       
                                h += txtH;
 
                        var ratio:Number = w/h;
 
                        if (ratio > 1)
                        {
                                _holder.height = _holder.width / ratio;
                        }
                        else
                        {
                                _holder.width = _holder.height * ratio;
                        }
 
                        _face = new Sprite();
 
                        var bSize:Number = _borderSize * w / _holder.width;
                        _imageBorder = new Shape();
 
                        var mat:Matrix = new Matrix();
                        var colors:Array = [0x999999, _borderColor, 0x999999];
                        var alphas:Array = [1, 1, 1];
                        var ratios:Array = [0, 127, 255];
                        mat.createGradientBox((w + bSize * 2)*2, (h + bSize * 2)*2, Math.PI / 4, -(w + bSize * 2)/2, -(h + bSize * 2)/2);
 
                        _imageBorder.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, mat);
                        _imageBorder.graphics.drawRect(0, 0, w + bSize * 2, h + bSize * 2);
                        _imageBorder.graphics.endFill();
 
                        _face.addChild(_imageBorder);
                        _face.addChild(_bmp);
 
 
 
                        _title = new TextField();
                        _title.autoSize = TextFieldAutoSize.LEFT;
                        _title.multiline = false;
                        _title.wordWrap = true;
                        _title.selectable = false;
                        _title.mouseWheelEnabled = false;
                        _title.textColor = _titleColor;
 
                        var myFont:Font = new SegoeFont();
                        var textFormat:TextFormat = new TextFormat();
                        textFormat.font = myFont.fontName;
                        textFormat.size = 50;
 
                        _title.embedFonts = true;
                        _title.defaultTextFormat = textFormat;
 
                        _title.text = _data.imageData[_id].title;
 
                        _title.width = w;
                        _title.height = txtH;
 
                        _title.x = bSize;
                        _title.y = bSize + _bmp.height + (txtH + bSize - _title.textHeight)/2;
 
                        if (_data.showTitle)
                                _face.addChild(_title);
 
                        _flipBtn1 = new FlipButton();
                        _flipBtn1.width = 15 * w / _holder.width * (_data.thumbSize / 200);
                        _flipBtn1.height = _flipBtn1.width;
 
                        _flipBtn1.x = w + bSize - _flipBtn1.width - 10;
                        _flipBtn1.y = h + bSize - _flipBtn1.height - 10;
 
                        TweenMax.to(_flipBtn1.ic_mc, 0, {tint:_flipBtnColor, ease:Expo.easeOut});
 
                        _face.addChild(_flipBtn1);
 
                        _bmp.x = bSize;
                        _bmp.y = bSize;
 
                        _over = new _Over();
                        _over.x = bSize;
                        _over.y = bSize;
                        _over.addEventListener(MouseEvent.ROLL_OVER,ll);
                        function ll(Event:MouseEvent):void
                        {
                                _over.gotoAndPlay("open");
                        }
                        _face.addChild(_over);
 
                        _holder.width += _borderSize * 2;
                        _holder.height += _borderSize * 2;
 
                        _imageMaterial = new MovieMaterial(_face);
                        _imageMaterial.smooth = true;
                        _imageMaterial.autoUpdate = false;
                        _imageMaterial.interactive = true;
 
                        _holder.material = _imageMaterial;
                        _imageMaterial.smooth = true;
 
                        _back = new Sprite();
 
                        _textBackround = new Shape();
                        _textBackround.graphics.beginFill(_textBgColor);
                        _textBackround.graphics.drawRect(0, 0, w, h);
                        _textBackround.graphics.endFill();
 
                        _imageText = new TextField();
                        _imageText.autoSize = TextFieldAutoSize.LEFT;
                        _imageText.multiline = true;
                        _imageText.wordWrap = true;
                        _imageText.selectable = false;
                        _imageText.mouseWheelEnabled = false;
                        _imageText.textColor = _textColor;
 
                        var textFormat2:TextFormat = new TextFormat();
                        textFormat2.font = _textFont;
                        textFormat2.size = _textSize;
 
                        _imageText.defaultTextFormat = textFormat2;
 
                        var _textLinkNormalColor:uint = 0x00FFFF;
                        var _textLinkSelectedColor:uint = 0xFF00FF;
 
                        var style:StyleSheet = new StyleSheet();
                        style.setStyle("a:link",{textDecoration:"underline"});
 
                        _imageText.styleSheet = style;
 
                        _imageText.htmlText = _data.imageData[_id].text;
 
                        _imageText.width = w - bSize;
                        _imageText.height = h;
 
                        _textBorder = new Shape();
 
                        _textBorder.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, mat);
                        _textBorder.graphics.drawRect(0, 0, w + bSize * 2, h + bSize * 2);
                        _textBorder.graphics.endFill();
 
                        _back.addChild(_textBorder);
                        _back.addChild(_textBackround);
                        _back.addChild(_imageText);
 
                        _flipBtn2 = new FlipButton();
                        _flipBtn2.width = 15 * w / _holder.width * (_data.thumbSize / 200);
                        _flipBtn2.height = _flipBtn2.width;
 
                        _flipBtn2.x = w + bSize - _flipBtn1.width - 10;
                        _flipBtn2.y = h + bSize - _flipBtn2.height - 10;
 
                        TweenMax.to(_flipBtn2.ic_mc, 0, {tint:_flipBtnColor, ease:Expo.easeOut});
 
                        _back.addChild(_flipBtn2);
 
                        _textBackround.x = bSize;
                        _textBackround.y = bSize;
 
                        _imageText.x = bSize + bSize/2;
                        _imageText.y = bSize;
 
                        _textMaterial = new MovieMaterial(_back);
                        _textMaterial.scaleX = -1;
                        _textMaterial.offsetX += _back.width;
 
                        _textMaterial.smooth = true;
                        _textMaterial.autoUpdate = false;
                        _textMaterial.interactive = true;
 
                        _holder.back = _textMaterial;
 
                        dispatchEvent(new ThumbEvent(ThumbEvent.THUMB_LOAD, _id));
 
                        _holder.addEventListener(MouseEvent3D.MOUSE_UP, onClick);
 
                        disable();
 
                        info = null;
                }
 
                private function onImageError(ev:Event):void
                {
                        var str:String = "<font color='#FF0000'>Image file \"" + _data.imageData[_id].imagePath + "\" not found.";
                        dispatchEvent(new DataEvent(DataEvent.ERROR, str));
                }
 
                public function select(ev:MouseEvent3D):void
                {
                        TweenMax.to(_holder, .5, {z:-70 * (_data.thumbSize / 200), ease:Expo.easeOut});
                        TweenMax.to(_holder, .5, {scaleX:1.2, ease:Expo.easeOut});
                        TweenMax.to(_holder, .5, {scaleY:1.2, ease:Expo.easeOut});
                }
 
                public function deselect(ev:MouseEvent3D):void
                {
 
                        TweenMax.to(_holder, .5, {z:0, ease:Expo.easeOut});
                        TweenMax.to(_holder, .5, {scaleX:1, ease:Expo.easeOut});
                        TweenMax.to(_holder, .5, {scaleY:1, ease:Expo.easeOut});
                }
 
                private function onClick(ev:MouseEvent3D):void
                {
                        dispatchEvent(new ThumbEvent(ThumbEvent.THUMB_CLICK, _id));
                }
 
                public function flip(ev:MouseEvent):void
                {
                        if (_selected)
                        {
                                if (!_flipped)
                                {
 
                                        TweenMax.to(_holder, .5, {rotationY:180, ease:Expo.easeOut});
                                        _flipped = true;
                                }
                                else
                                {
                                        TweenMax.to(_holder, .5, {rotationY:0, ease:Expo.easeOut});
                                        _flipped = false;
                                }
                        }
 
                        if (ev == null)
                        {
                                TweenMax.to(_holder, .5, {rotationY:0, ease:Expo.easeOut});
                                _flipped = false;
                        }
                }
 
                public function enable():void
                {
                        _selected = true;
 
                        _flipBtn1.alpha = 1;
                        _flipBtn2.alpha = 1;
 
                        _flipBtn1.addEventListener(MouseEvent.CLICK, flip);
                        _flipBtn2.addEventListener(MouseEvent.CLICK, flip);
 
                        _imageMaterial.update();
                        _textMaterial.update();
 
                        _holder.removeEventListener(MouseEvent3D.MOUSE_OVER, select);
                        _holder.removeEventListener(MouseEvent3D.MOUSE_OUT, deselect);
                        _holder.removeEventListener(MouseEvent3D.MOUSE_UP, onClick);
                }
 
                public function disableMouseOver():void
                {
                        _holder.removeEventListener(MouseEvent3D.MOUSE_OVER, select);
                        _holder.removeEventListener(MouseEvent3D.MOUSE_OUT, deselect);
                }
 
                public function disable():void
                {
                        if (_flipBtn2 != null)
                        {
                                _selected = false;
 
                                _flipBtn1.alpha = 0;
                                _flipBtn2.alpha = 0;
 
                                _flipBtn1.removeEventListener(MouseEvent.CLICK, flip);
                                _flipBtn2.removeEventListener(MouseEvent.CLICK, flip);
 
                                _imageMaterial.update();
                                _textMaterial.update();
 
                                _holder.addEventListener(MouseEvent3D.MOUSE_OVER, select);
                                _holder.addEventListener(MouseEvent3D.MOUSE_OUT, deselect);
                                _holder.addEventListener(MouseEvent3D.MOUSE_UP, onClick);
                        }
                }
 
                public function destroy():void
                {
                        _holder.removeEventListener(MouseEvent3D.MOUSE_OVER, select);
                        _holder.removeEventListener(MouseEvent3D.MOUSE_OUT, deselect);
                        _holder.removeEventListener(MouseEvent3D.MOUSE_UP, onClick);
 
                        _flipBtn1.removeEventListener(MouseEvent.CLICK, flip);
                        _flipBtn2.removeEventListener(MouseEvent.CLICK, flip);
 
                        _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, setThumb);
                        _loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onImageError);
 
                        _imageMaterial.autoUpdate = false;
                        _imageMaterial.smooth = false;
                        _imageMaterial.interactive = false;
 
                        _textMaterial.autoUpdate = false;
                        _textMaterial.smooth = false;
                        _textMaterial.interactive = false;
 
                        _imageMaterial.bitmap.dispose();
                        _textMaterial.bitmap.dispose();
 
                        _bmp.bitmapData.dispose();
 
                        _imageMaterial = null;
                        _textMaterial = null;
 
                        _flipBtn1 = null;
                        _flipBtn2 = null;
 
                        _loader = null;
 
                        _holder.ownCanvas = false;
                        _holder.material = null;
                        _holder.back = null;
 
                        _bmp = null;
                        _face = null;
                        _back = null;
                        _imageBorder = null;
                        _textBorder = null;
                        _textBackround = null;
                        _data = null;
                        _imageText = null;
                        _title = null;
                        _holder = null;
                }
 
                public function get id():int
                {
                        return _id;
                }
 
                public function get holder():Plane
                {
                        return _holder;
                }
 
                public function get selected():Boolean
                {
                        return _selected;
                }
 
                public function set selected(pSelected:Boolean):void
                {
                        _selected = pSelected;
                }
 
                public function get flipped():Boolean
                {
                        return _flipped;
                }
 
                public function set flipped(pFlipped:Boolean):void
                {
                        _flipped = pFlipped;
                }
        }
}

Это код, для каждого мувика, загружаемого в контейнер через xml. Вопрос следующий.. Мне нужно сделать Roll_over/Out помимо того, что _handler ресайзится. Я создал в библиотеке клип _Over c графикой и гружу его в "_face" _face.addChild(_over),прописываю листенер на _over но безрезультатно. Далее я попробовал прописать _over.gotoAndPlay("open") в ф-цию _holder.addEventListener(MouseEvent3D.MOUSE_UP, onClick); но тоже безрезультатно. Потом увидел что _face уходит в material (_imageMaterial = new MovieMaterial(_face);), в свою очередь _holder.material = _imageMaterial; Подскажите можно ли как-то проложить путь к моему мувику (_over) через material? если нет то как можно решить эту задачу?

Wolsh 15.04.2013 21:55

1. Название темы не отражает сути вопроса.
2. Раздел выбран неверно. Сторонние API обсуждаются в разделе API приложений и сред.


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

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