Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   класс SWFAddressEvent и ошибка 5007 (http://www.flasher.ru/forum/showthread.php?t=157094)

Di_al 31.05.2011 16:47

класс SWFAddressEvent и ошибка 5007
 
Возникла такая проблема:
есть SWFAddressEvent.as,SWFAddress.as и main.fla файлом. При компиляции флеш выдает ошибку 5007:An ActionScript file must have at least one externally visible definition. И при этом указывает на класс SWFAddressEvent, который в наглую скачан с безграничных просторов интернета. Код класса выглядит следующим образом:
Код AS3:

import SWFAddress;
 
class SWFAddressEvent {
 
    public static var INIT:String = 'init';
    public static var CHANGE:String = 'change';
 
    private var _type:String;
    private var _value:String;
    private var _path:String;
    private var _pathNames:Array;
    private var _parameters:Object;
    private var _parametersNames:Array;
 
    public function SWFAddressEvent(type:String) {
        _type = type;
        _value = SWFAddress.getValue();
        _path = SWFAddress.getPath();
        _pathNames = SWFAddress.getPathNames();
        _parameters = new Array();
        _parametersNames = SWFAddress.getParameterNames();
        for (var i:Number = 0; i < _parametersNames.length; i++) {
            _parameters[_parametersNames[i]] = SWFAddress.getParameter(_parametersNames[i]);
        }       
    }
 
    public function get type():String {
        return _type;
    }
 
    public function get target():Object {
        return SWFAddress;
    }
 
    public function get value():String {
        return _value;
    }
 
    public function get path():String {
        return _path;
    }
 
    public function get pathNames():Array {
        return _pathNames;
    }
 
    public function get parameters():Object {
        return _parameters;
    }
 
    public function get parametersNames():Array {
        return _parametersNames;
    }   
}

Так как я только с недавних пор пытаюсь пересесть с Action Script2.0 на 3.0, то даже не особо могу определить в чем кроется ошибка: то ли в расположении файлов, то ли чего то не хватает в самом коде?

tsarapkabel 31.05.2011 18:30

Цитата:

class SWFAddressEvent {
Заменить на
Код AS3:

public class SWFAddressEvent {


Di_al 31.05.2011 18:38

Цитата:

Сообщение от tsarapkabel (Сообщение 1000129)
Заменить на
Код AS3:

public class SWFAddressEvent {


Хмммм..... а теперь он выдал новую ошибку, что атрибуты класса могут использоваться только внутри %(
Звучит вот так:
Код AS3:

C:\Users\Xmel\Desktop\Anls\5\SWFAddressEvent.as, Line 11        1114: The public attribute can only be used inside a package.


tsarapkabel 31.05.2011 21:49

В самом начале добавить

Код AS3:

package {

и закрыть в конце.

Di_al 31.05.2011 22:13

Пробовала. Увы ошибка 5007 сохраняется :(

tsarapkabel 31.05.2011 22:37

Вот так всё работает, при условии, что класс SWFAddress импортируется.
Код AS3:

package {
 
        import SWFAddress;
 
        public class SWFAddressEvent {
 
                public static var INIT:String = 'init';
                public static var CHANGE:String = 'change';
 
                private var _type:String;
                private var _value:String;
                private var _path:String;
                private var _pathNames:Array;
                private var _parameters:Object;
                private var _parametersNames:Array;
 
                public function SWFAddressEvent(type:String) {
                        _type = type;
                        _value = SWFAddress.getValue();
                        _path = SWFAddress.getPath();
                        _pathNames = SWFAddress.getPathNames();
                        _parameters = new Array();
                        _parametersNames = SWFAddress.getParameterNames();
                        for (var i:Number = 0; i < _parametersNames.length; i++) {
                                _parameters[_parametersNames[i]] = SWFAddress.getParameter(_parametersNames[i]);
                        }       
                }
 
                public function get type():String {
                        return _type;
                }
 
                public function get target():Object {
                        return SWFAddress;
                }
 
                public function get value():String {
                        return _value;
                }
 
                public function get path():String {
                        return _path;
                }
 
                public function get pathNames():Array {
                        return _pathNames;
                }
 
                public function get parameters():Object {
                        return _parameters;
                }
 
                public function get parametersNames():Array {
                        return _parametersNames;
                }
        }
}


Di_al 31.05.2011 22:55

Кхм.... И как же тогда вывернуться из сложившейся ситуации??? Попробовала поперемещать класс он либо говорит, что класс не в той папке, либо, если удалить, что класс не найден. Когда класс с ним рядом, ошибок импортирования нет. А 5007 все равно осталась :(

tsarapkabel 31.05.2011 23:12

Выложи SWFAddress.as (можно только код) и main.fla.

Di_al 31.05.2011 23:34

боюсь, что этим обойтись не выйдет-проект довольно масштабный. Выложила его вот сюда
сюда

tsarapkabel 01.06.2011 00:19

Всё работает. Ещё раз по порядку: 1) package 2) две фигурные скобки 3) public 4) сохраняемся 5) profit

Далее он выдаёт кучу ошибок "1046", однако если применить Автоформат (наверху 4-я иконка слева в редакторе кода Flash IDE), останутся только косяки с

Код AS3:

ExternalInterface.addCallback('getSWFAddressValue', SWFAddress, ;
                                function():String {return this._value});

Полагаю, что уход от анонимных функций решит эту проблему.

Di_al 01.06.2011 00:33

Да. Там все по этой инструкции(если profit означает запуск по вашему). Но у меня все равно упорно ошибка 5007. Может все дело в настройках компилятора и там надо прописать какие нибудь пути?Я просто уже начинаю отчаиваться :(

tsarapkabel 01.06.2011 01:02

А так?
Код AS3:

package {
 
        import flash.external.ExternalInterface;
        import mx.events.EventDispatcher;
        import SWFAddressEvent;
 
        public class SWFAddress {
 
                private static var _init:Boolean = false;
                private static var _strict:Boolean = true;
                private static var _value:String = '';
                private static var _interval:Number;
                private static var _availability:Boolean = ExternalInterface.available;
                private static var _dispatcher:EventDispatcher = new EventDispatcher();
                private static var _initializer:Boolean = _initialize();
 
                public static var onInit:Function;
                public static var onChange:Function;
 
                private static function _initialize():Boolean {
                        if (_availability) {
                                ExternalInterface.addCallback('getSWFAddressValue', SWFAddress, ;
                                function():String {return this._value});
                                ExternalInterface.addCallback('setSWFAddressValue', SWFAddress,
                                                SWFAddress._setValue);
                        }
                        if (typeof _level0.$swfaddress != 'undefined') {
                                SWFAddress._value = _level0.$swfaddress;
                        }
                        _interval = setInterval(SWFAddress._check,10);
                        return true;
                }
 
                private static function _check():Void {
                        if ((typeof SWFAddress.onInit == 'function' || typeof _dispatcher['__q_init'] != 'undefined') && !_init) {
                                SWFAddress._setValueInit(_getValue());
                                SWFAddress._init = true;
                        }
                        if (typeof SWFAddress.onChange == 'function' || typeof _dispatcher['__q_change'] != 'undefined') {
                                clearInterval(_interval);
                                SWFAddress._init = true;
                                SWFAddress._setValueInit(_getValue());
                        }
                }
 
                private static function _strictCheck(value:String, force:Boolean):String {
                        if (SWFAddress.getStrict()) {
                                if (force) {
                                        if (value.substr(0,1) != '/') {
                                                value = '/' + value;
                                        }
                                } else {
                                        if (value == '') {
                                                value = '/';
                                        }
                                }
                        }
                        return value;
                }
 
                private static function _getValue():String {
                        var value:String,id:String = 'null';
                        if (_availability) {
                                value = String(ExternalInterface.call('SWFAddress.getValue'));
                                id = String(ExternalInterface.call('SWFAddress.getId'));
                        }
                        if (id == 'undefined' || id == 'null' || !_availability) {
                                value = SWFAddress._value;
                        } else {
                                if (value == 'undefined' || value == 'null') {
                                        value = '';
                                }
                        }
                        return _strictCheck(value || '', false);
                }
 
                private static function _setValueInit(value:String):Void {
                        SWFAddress._value = value;
                        if (! _init) {
                                _dispatchEvent('init');
                        } else {
                                _dispatchEvent('change');
                        }
                }
 
                private static function _setValue(value:String):Void {
                        if (value == 'undefined' || value == 'null') {
                                value = '';
                        }
                        if (SWFAddress._value == value && SWFAddress._init) {
                                return;
                        }
                        SWFAddress._value = value;
                        if (! _init) {
                                SWFAddress._init = true;
                                if (typeof SWFAddress.onInit == 'function' || typeof _dispatcher['__q_init'] != 'undefined') {
                                        _dispatchEvent('init');
                                }
                        }
                        _dispatchEvent('change');
                }
 
                private static function _dispatchEvent(type:String):Void {
                        if (typeof _dispatcher['__q_' + type] != 'undefined') {
                                _dispatcher.dispatchEvent(new SWFAddressEvent(type));
                        }
                        type = type.substr(0,1).toUpperCase() + type.substring(1);
                        if (typeof SWFAddress['on' + type] == 'function') {
                                SWFAddress['on' + type]();
                        }
                }
 
                public static function toString():String {
                        return '[class SWFAddress]';
                }
 
                public static function back():Void {
                        if (_availability) {
                                ExternalInterface.call('SWFAddress.back');
                        }
                }
 
                public static function forward():Void {
                        if (_availability) {
                                ExternalInterface.call('SWFAddress.forward');
                        }
                }
 
                public static function go(delta:Number):Void {
                        if (_availability) {
                                ExternalInterface.call('SWFAddress.go', delta);
                        }
                }
 
                public static function href(url:String, target:String):Void {
                        target = (typeof target != 'undefined') ? target : '_self';
                        if (_availability && System.capabilities.playerType == 'ActiveX') {
                                ExternalInterface.call('SWFAddress.href', url, target);
                                return;
                        }
                        getURL(url, target);
                }
 
                public static function popup(url:String, name:String, options:String, handler:String):Void {
                        name = (typeof name != 'undefined') ? name : 'popup';
                        options = (typeof options != 'undefined') ? options : '';
                        handler = (typeof handler != 'undefined') ? handler : '';
                        if (_availability && System.capabilities.playerType == 'ActiveX') {
                                ExternalInterface.call('SWFAddress.popup', url, name, options, handler);
                                return;
                        }
                        getURL('javascript:popup=window.open("' + url + '","' + name + '",' + options + ');' + handler);
                }
 
                public static function addEventListener(type:String, listener:Function):Void {
                        _dispatcher.addEventListener(type, listener);
                }
 
                public static function removeEventListener(type:String, listener:Function):Void {
                        _dispatcher.removeEventListener(type, listener);
                }
 
                public static function dispatchEvent(event:Object):Void {
                        _dispatcher.dispatchEvent(event);
                }
 
                public static function hasEventListener(type:String):Boolean {
                        return (typeof _dispatcher['__q_' + type] != 'undefined');
                }
 
                public static function getBaseURL():String {
                        var url:String = 'null';
                        if (_availability) {
                                url = String(ExternalInterface.call('SWFAddress.getBaseURL'));
                        }
                        return (url == 'undefined' || url == 'null' || !_availability) ? '' : url;
                }
 
                public static function getStrict():Boolean {
                        var strict:String = 'null';
                        if (_availability) {
                                strict = String(ExternalInterface.call('SWFAddress.getStrict'));
                        }
                        return (strict == 'null' || strict == 'undefined') ? _strict : (strict == 'true');
                }
 
                public static function setStrict(strict:Boolean):Void {
                        if (_availability) {
                                ExternalInterface.call('SWFAddress.setStrict', strict);
                        }
                        _strict = strict;
                }
 
                public static function getHistory():Boolean {
                        return Boolean((_availability) ?
                                    ExternalInterface.call('SWFAddress.getHistory') : false);
                }
 
                public static function setHistory(history:Boolean):Void {
                        if (_availability) {
                                ExternalInterface.call('SWFAddress.setHistory', history);
                        }
                }
 
                public static function getTracker():String {
                        return (_availability) ?
                                    String(ExternalInterface.call('SWFAddress.getTracker')) : '';
                }
 
                public static function setTracker(tracker:String):Void {
                        if (_availability) {
                                ExternalInterface.call('SWFAddress.setTracker', tracker);
                        }
                }
 
                public static function getTitle():String {
                        var title:String = (_availability) ?
                                    String(ExternalInterface.call('SWFAddress.getTitle')) : '';
                        if (title == 'undefined' || title == 'null') {
                                title = '';
                        }
                        return title;
                }
 
                public static function setTitle(title:String):Void {
                        if (_availability) {
                                ExternalInterface.call('SWFAddress.setTitle', title);
                        }
                }
 
                public static function getStatus():String {
                        var status:String = (_availability) ?
                                    String(ExternalInterface.call('SWFAddress.getStatus')) : '';
                        if (status == 'undefined' || status == 'null') {
                                status = '';
                        }
                        return status;
                }
 
                public static function setStatus(status:String):Void {
                        if (_availability) {
                                ExternalInterface.call('SWFAddress.setStatus', status);
                        }
                }
 
                public static function resetStatus():Void {
                        if (_availability) {
                                ExternalInterface.call('SWFAddress.resetStatus');
                        }
                }
 
                public static function getValue():String {
                        return _strictCheck(_value || '', false);
                }
 
                public static function setValue(value:String):Void {
                        if (value == 'undefined' || value == 'null') {
                                value = '';
                        }
                        value = _strictCheck(value,true);
                        if (SWFAddress._value == value) {
                                return;
                        }
                        SWFAddress._value = value;
                        if (_availability) {
                                ExternalInterface.call('SWFAddress.setValue', value);
                        }
                        _dispatchEvent('change');
                }
 
                public static function getPath():String {
                        var value:String = SWFAddress.getValue();
                        if (value.indexOf('?') != -1) {
                                return value.split('?')[0];
                        } else {
                                return value;
                        }
                }
 
                public static function getPathNames():Array {
                        var path:String = SWFAddress.getPath();
                        var names:Array = path.split('/');
                        if (path.substr(0,1) == '/') {
                                names.splice(0, 1);
                        }
                        if (path.substr(path.length - 1,1) == '/') {
                                names.splice(names.length - 1, 1);
                        }
                        return names;
                }
 
                public static function getQueryString():String {
                        var value:String = SWFAddress.getValue();
                        var index:Number = value.indexOf('?');
                        if (index != -1 && index < value.length) {
                                return value.substr(index + 1);
                        }
                        return '';
                }
 
                public static function getParameter(param:String):String {
                        var value:String = SWFAddress.getValue();
                        var index:Number = value.indexOf('?');
                        if (index != -1) {
                                value = value.substr(index + 1);
                                var params:Array = value.split('&');
                                var p:Array;
                                var i:Number = params.length;
                                while (i--) {
                                        p = params[i].split('=');
                                        if (p[0] == param) {
                                                return p[1];
                                        }
                                }
                        }
                        return '';
                }
 
                public static function getParameterNames():Array {
                        var value:String = SWFAddress.getValue();
                        var index:Number = value.indexOf('?');
                        var names:Array = new Array();
                        if (index != -1) {
                                value = value.substr(index + 1);
                                if (value != '' && value.indexOf('=') != -1) {
                                        var params:Array = value.split('&');
                                        var i:Number = 0;
                                        while (i < params.length) {
                                                names.push(params[i].split('=')[0]);
                                                i++;
                                        }
                                }
                        }
                        return names;
                }
        }
}


Di_al 01.06.2011 02:42

Да!!!
Теперь действительно остались только косяки с
Код AS1/AS2:

 ExternalInterface.addCallback('getSWFAddressValue', SWFAddress, ;
                                function():String {return this._value});

Спасибо, попробую разгребсти)


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

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