Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 1.0/2.0 (http://www.flasher.ru/forum/forumdisplay.php?f=93)
-   -   Положение мувиклипа (http://www.flasher.ru/forum/showthread.php?t=112720)

Eugenicsbmx 06.06.2008 01:43

Положение мувиклипа
 
Добрый день вот код в сцене:
Код:


fscommand("allowscale", "false");

//Стиль для текса подписей (CSS)
var styles = new TextField.StyleSheet();
styles.setStyle("bodyText",
  {fontFamily: 'myTahoma',
  color: '#ffffff',
  textAlign: 'center',
  fontSize: '12px' }
 
);



this.dockActions = function(label) {
        switch(label) {
                case 'Background':
                        getURL("javascript: HideBrowser(); HideLogin();");
                        break;
                case 'About':
                        getURL("text.php?id=1", "MainFrame");
                        getURL("javascript: ShowBrowser();");
                        break;
                case 'Sites':
                        getURL("text.php?id=2", "MainFrame");
                        getURL("javascript: ShowBrowser();");
                        break;
                case 'Graphics':
                        getURL("text.php?id=3", "MainFrame");
                        getURL("javascript: ShowBrowser();");
                        break;
                case 'Flash':
                        getURL("www.flasher.ru");
                        getURL("javascript: ShowBrowser();");
                        break;
                case 'Contacts':
                        getURL("text.php?id=5", "MainFrame");
                        getURL("javascript: ShowBrowser();");
                        break;
                case 'Secret':
                        getURL("javascript:        ShowLogin();");
                        break;
                default:
                        getURL("404.html", "_top");
        }
}

switch(_root.language) {
        case 'lv':
                var myArray = [
                                { id: 'background', label: 'Background', description: 'Aizvērt logus' },
                                { id: 'myUsers', label: 'About', description: 'Par mums' },
                                { id: 'mySites', label: 'Sites', description: 'Saites' },
                                { id: 'myGraphics',label: 'Graphics', description: 'Grafika' },
                                { id: 'myFlash', label: 'Flash', description: 'Flash' },
                                { id: 'myContacts', label: 'Contacts', description: 'Kontakti' },
                                { id: 'myLock', label: 'Secret', description: 'Slēptā sadaļa' }
                        ];
                break;
        case 'en':
                var myArray = [
                                { id: 'background', label: 'Background', description: 'Hide window' },
                                { id: 'myUsers', label: 'About', description: 'About us' },
                                { id: 'mySites', label: 'Sites', description: 'Sites' },
                                { id: 'myGraphics',label: 'Graphics', description: 'Graphics' },
                                { id: 'myFlash', label: 'Flash', description: 'Flash' },
                                { id: 'myContacts', label: 'Contacts', description: 'Contacts' },
                                { id: 'myLock', label: 'Secret', description: 'Log In' }
                        ];
                break;
        default:
                var myArray = [
                               
                                { id: 'Films', label: 'Films', description: 'Кіно' },
                                { id: 'Musik', label: 'Musik', description: 'Музика' },
                                { id: 'Forum',label: 'Graphics', description: 'Форум' },
                                { id: 'Office', label: 'Flash', description: 'Мій кабінет' },
                                { id: 'Failu', label: 'Failu', description: 'Файли' }
                               
                        ];
}

var dockTemplate = {
        layout: "center", /* top | right | bottom | left | *rotation* */
        icon_size: 128,
        icon_min: 70,
        icon_max: 128,
        icon_spacing: 30,
        items: myArray,
        span: 170,
        amplitude: 90,
        callback: this.dockActions
}

this.attachMovie('Dock', 'menu_mc', 1, dockTemplate);
this.menu_mc._x = Stage.width / 2;
this.menu_mc._y = Stage.height/  2;


Eugenicsbmx 06.06.2008 01:44

Вот класс подгружаемый в сцену
Код:





class Dock extends MovieClip {
        var vz:Boolean=false;// Изчезновение
   
    function onLoad() {
        this._alpha = 5;
        vz = false;
    }

    function onRollOver() {
        vz = true;
    }
    function onRollOut() {
        vz = false;
    } // Изчезновение

        var icon_min                : Number;        //Минималный размер иконки.
        var icon_max                : Number;        //Максимальный размер иконки.
        var icon_size                : Number;        //Натуральный размер иконки.
        var icon_spacing        : Number;        //Промежутки между иконками
        var width                        : Number;        //Ширина чего-то (!)
        var span                        : Number;        //Задействованные иконки про движении (длинна).
        var amplitude                : Number;        //Для нужд класса
        var ratio                        : Number;        //Для нужд класса
        var scale                        : Number = Number.NEGATIVE_INFINITY; //Хз
        var trend                        : Number = 0;        //Хз
        var xmouse                        : Number;        //Позиция крысы
        var ymouse                        : Number;        //Сэйм шит
        var layout                        : String;        //Вывод..
        var callback                : Function;        //Функция
        var items                        : Array;        //Массив элементов

        function Dock() {                //Инициализация класса Dock
                setParameters();
                setLayout();
                createIcons();
                createTray();
                onEnterFrame = monitorDock;        //Мониторинг менюшки..
        }

        private function setParameters():Void {
                this.layout = this.layout ? this.layout : 'bottom';                                                //Если параметр this.layout не задан, то положение менюшки снизу
                this.icon_min = this.icon_min ? this.icon_min : 32;                                                //Если не задан минимальный размер то он 32
                this.icon_max = this.icon_max ? this.icon_max : 96;                                                //-||- максимальный, то он 96
                this.icon_spacing = this.icon_spacing ? this.icon_spacing : 2;                        // Расстояние между иконками.
                this.span = this.span ? this.span : getSpan();                                                        // если не заданно растяжение,то оно вычисляется..
                this.amplitude = this.amplitude ? this.amplitude : getAmplitude();
                this.ratio =  Math.PI / 2 / this.span;
        }

        private function getSpan():Number {                        //Функция задействованной области.
                return (this.icon_min - 16) * (240 - 60) / (96 - 16) + 60;
        }

        private function getAmplitude():Number {        //Функция вычисления длинны волны.
                return 2 * (this.icon_max - this.icon_min + this.icon_spacing);
        }

        private function createIcons():Void {                //Функция рисования иконок.
                var i:Number;                                                        //Кол-во иконок.
                var id:String;                                                        //Наименование иконки.
                this.scale = 0;                                                        //Жуй знает
                this.width = (this.items.length - 1) * this.icon_spacing + this.items.length * this.icon_min;        //Просчёт ширины (полоски)
                var left:Number = (this.icon_min - this.width) / 2;  //Смещение влево при наведении (центровка)
                for(i = 0; i < this.items.length; i++) {        //Пробегаемся циклом по массиву
                        this.createEmptyMovieClip(String(i), 10 + i).attachMovie(this.items[i].id, '_mc', 1);        //Создаём мувиклип иконки
                        this[i]._mc._y = -this.icon_size / 2;                //Смещение контейнера.
                        this[i]._mc._rotation = -this._rotation;        //Поворот иконки(!)
                        this[i]._x = this[i].x = left + i * (this.icon_min + this.icon_spacing) + this.icon_spacing / 2; //Смещение иконки.
                        this[i]._y = -this.icon_spacing;        // --||--
                        this[i].onRelease = launchIcon;                // Вызов функции при нажатии.
                        this[i].onRollOver = createMouseCursor;                // Вызов функции при наведении.
                        this[i].onRollOut = destroyMouseCursor;                // Вызов функции при "Уведении" :).
                        //this[i].useHandCursor = false;                // Убрать курсор руки.
                       
                        this[String(i)].createTextField('mytext', this.getNextHighestDepth(), -64, -14, 128, 16); // Создание непосредственно самого текстового поля
                        with(this[String(i)].mytext) {
                                styleSheet = _root.styles;
                                htmlText = "<bodyText>" + this.items[i].description + "</bodyText>";
                                embedFonts = true;
                        }
                }
        }

        private function launchIcon():Void {                //Функция, вызванная нажатием.
                this._parent.callback(this._parent.items[this._name].label); //Вызов функции описанной в мвиклипе.
        }

        private function createMouseCursor():Void {
                Mouse.hide();
                _root.attachMovie('cursor', 'cursor', _root.getNextHighestDepth(), {_x: _root._xmouse, _y: _root._ymouse});
                _root.cursor.startDrag(true);
                updateAfterEvent();
        }

        private function destroyMouseCursor():Void {
                Mouse.show();
                _root.cursor.removeMovieClip();
        }

        private function createTray():Void {                //Рисование заднего фона (програмное \м/)
                var height:Number = this.icon_min - 2 * this.icon_spacing; // изменил "+" на "-" (Я)
                var width:Number = this.width - 2 * this.icon_spacing; // изменил "+" на "-" (Я)
                var mc:MovieClip = this.createEmptyMovieClip('tray_mc', 1);
                //mc.lineStyle(0, 0xcccccc, 80);
                //mc.beginFill(0xe8e8e8, 50);
                //mc.lineTo(0, -height);
                //mc.lineTo(width, -height);
                //mc.lineTo(width, 0);
                //mc.lineTo(0, 0);
                //mc.endFill();
        }

        private function setLayout():Void {                //Определяется вывод меню
                switch(this.layout) {
                        case 'left':
                                this._rotation = 90;
                                break;
                        case 'top':
                                this._rotation = 180;
                                break;
                        case 'right':
                                this._rotation = 270;
                                break;
                        default:
                                this._rotation = Number(this.layout);
                }
        }

        private function checkBoundary():Boolean {        //Выявление границы, в которых задействованна крыса :) ну и намутили...
                var buffer:Number = 4 * this.scale;
                return (this.ymouse < 1)
                        && (this.ymouse > -2 * this.icon_spacing - this.icon_min + (this.icon_min - this.icon_max) * this.scale)
                        && (this.xmouse > this[0]._x - this[0]._width / 2 - this.icon_spacing - buffer)
                        && (this.xmouse < this[this.items.length - 1]._x + this[this.items.length - 1]._width / 2 + this.icon_spacing + buffer);
        }

        private function updateTray():Void {                // Обновление ширины задней полоски.
                var x:Number;
                var w:Number;
                x = this[0]._x - this[0]._width / 2 - this.icon_spacing;
                w = this[this.items.length - 1]._x + this[this.items.length - 1]._width / 2 + this.icon_spacing;
                this['tray_mc']._x = x;
                this['tray_mc']._width = w - x;
        }

        private function monitorDock():Boolean {        //Функция отслеживания
                var i:Number;
                var x:Number;
                var dx:Number;
                var dim:Number;
                if (vz == true) {                  // Изчезновение
            if (this._alpha<100) {
                this._alpha += 5;
            }
        }
        if (vz == false) {
            if (this._alpha>=10) {
                this._alpha -= 5;
            }
        }                                  // Изчезновение

                // Крыса не двигается и меню не находится между стадиями
                if((this.xmouse == this._xmouse) && (this.ymouse == this._ymouse) && ((this.scale <= 0.01) || (this.scale >= 0.99))) { return false; }

                // Крыса двинулась или меню во время стадии. Обновить док.
                this.xmouse = this._xmouse;
                this.ymouse = this._ymouse;

                // Гарантия, что задействование не изменит направление (???)
                this.trend = (this.trend == 0 ) ? (checkBoundary() ? 0.25 : -0.25) : (this.trend);
                this.scale += this.trend;
                if( (this.scale < 0.02) || (this.scale > 0.98) ) { this.trend = 0; }

                // Натуральный размер нахдится между 0 и 1
                this.scale = Math.min(1, Math.max(0, this.scale));

                // Жуть редкая :) вычисление позиций иконок и просчёт их размера ;)
                for(i = 0; i < this.items.length; i++) {
                        dx = this[i].x - this.xmouse;
                        dx = Math.min(Math.max(dx, -this.span), this.span);
                        dim = this.icon_min + (this.icon_max - this.icon_min) * Math.cos(dx * this.ratio) * (Math.abs(dx) > this.span ? 0 : 1) * this.scale;
                        this[i]._x = this[i].x + this.scale * this.amplitude * Math.sin(dx * this.ratio);
                        this[i]._xscale = this[i]._yscale =  100 * dim / this.icon_size;
                        this[String(i)].mytext._alpha = (this[i]._xscale - 38) * 2;
                }

                // Изменить размер задника.
                updateTray();
                return true;
        }

}

Никак не могу откалибровать положение мувика на сцене, незнаю где именно те параметры что нужно изменить юзал вот эти:
Код:

var dockTemplate = {
        layout: "center", /* top | right | bottom | left | *rotation* */
        icon_size: 128,
        icon_min: 70,
        icon_max: 128,
        icon_spacing: 30,
        items: myArray,
        span: 170,
        amplitude: 90,
        callback: this.dockActions
}

this.attachMovie('Dock', 'menu_mc', 1, dockTemplate);
this.menu_mc._x = Stage.width / 2;
this.menu_mc._y = Stage.height/  2;

Ширину длину когда меняешь меняет и положение мувик, но он как то странно себя ведет и меняет положение как попало.:moder:

Psycho Tiger 06.06.2008 15:37

Попробуйте удалить половину кода, сохраняя проблему - разобраться в вашем коде достаточно сложно, особенно учитывая то, что это не один ас (в библиотеке у вас тоже есть клипы)

Eugenicsbmx 06.06.2008 16:38

один клип Dock на сцене его нет...больше нету

Волгоградец 06.06.2008 17:35

Код:

this.attachMovie('Dock', 'menu_mc', 1, dockTemplate, {_x: 100, _y: 100});
если это имелось ввиду

Eugenicsbmx 06.06.2008 18:05

Попробывал вообще не меняет положения
вот этип получается только как то странно оно его смещает:
Код:

this.attachMovie('Dock', 'menu_mc', 1, dockTemplate);
this.menu_mc._x = Stage.width / 2;
this.menu_mc._y = Stage.height/  2;

меняю 2-ки,

Eugenicsbmx 07.06.2008 02:01

Код:

private function setParameters():Void {
            this.layout = this.layout ? this.layout : 'midlle';

Если положение не указано, то оно снизу, а можно вместо мидл написать положение по х и y, я не знаю как правильно написать...


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

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