Реализация в контэйнере браузерных кнопок назад и вперед

Только готовые уроки по использованию ВКонтакте API. Flash + PHP + API. НЕ IFrame!
Ответить
Аватара пользователя
BANAN
Сообщения: 96
Зарегистрирован: 10 мар 2010, 22:24

Реализация в контэйнере браузерных кнопок назад и вперед

Сообщение BANAN »

Нам понадобится настроенный FlashDevelop (по его настройке см. тут)
После того как всё настроили, запускаете его.
Далее на вкладке Project выбираете New Project.
В открывшемся окне выбираем AS3 Project, чуть ниже указываем Name ("Test") и Location (любой путь)
(Галочку "Create directory for project" не снимать.)
Далее жмем ок.
В нашей папке Test будет создано 3 папки: bin (тут будет хранится наш Test.swf), lib, src.
В папке src должен быть следующий файл Main.as
Его тект:

Код: Выделить всё

package {    import flash.display.*;    import flash.events.*;    import flash.system.*;    import flash.text.*;    import vk.*;    import vk.gui.*;    import flash.net.*;   public class Main extends Sprite {                public var wrapper:* = null;        private var menu:* = null;        private var menu_item1:* = null;        private var menu_item2:* = null;        private var cur_full_loc:String = null;        private var cur_loc:String = null;            public function Main():void     {        if (stage) init();        else addEventListener(Event.ADDED_TO_STAGE, init);    }        private function init(e:Event = null):void     {        wrapper = Object(parent.parent);        if ( wrapper.external == null )          wrapper = stage;        wrapper.addEventListener( 'onLocationChanged', onLocationChanged );                 var bg:Sprite = new Sprite();        Utils.fillRect( bg, 0, 0, 627, 4050, Utils.BK_COL );        addChild( bg );             menu = VK.createMainMenu( wrapper );        menu_item1 = menu.addItem( "Menu Item 1", "loc1" );        menu_item2 = menu.addItem( "Menu Item 2", "loc2" );        addChild( menu );          menu.addEventListener( Event.CHANGE, onMenu );                if ( cur_full_loc )          onLocationChanged( {location:cur_full_loc} );        else        if ( wrapper is Stage )          onLocationChanged( { location:"loc1" } );    }                    private function goTo( loc:String ):void    {        if ( !(wrapper is Stage)  &&  cur_full_loc != loc )          wrapper.external.setLocation( loc, true );        else          onLocationChanged( {location:loc} );    }     private function onLocationChanged( e:* ):void    {         cur_full_loc = e.location;            var def:String = "loc1";       if ( cur_full_loc.length == 0 )        cur_full_loc = def;              var arr:Array = cur_full_loc.split( "/" );      var mnu_item:String = arr[0] || def;            cur_loc = mnu_item + "/";            if ( menu == null )        return;       menu.setLocation( mnu_item );       switch ( mnu_item )      {      case "loc1":        menu.selectedItem.panel.addChild( VK.addText( "Menu Item Navigated: " + cur_loc, 200, 200 ) );        break;              case "loc2":       menu.selectedItem.panel.addChild( VK.addText( "Menu Item Navigated: " + cur_loc, 200, 200 ) );        break;             default:                break;      }    }     private function onMenu( e:Event ):void    {        if ( e.target is MainMenu )        goTo( e.target.selectedLocation );    }  }} 
Извиняюсь за корявый код, лень выравнивать))

Далее в папке src должна быть папка vk. В ней должен быть файл VK.as
Его код:

Код: Выделить всё

package vk{  import vk.*;  import vk.gui.*;  public class VK  {   /* public static var MainMenu:Class = null;    public static var RoundButton:* = null;    public static var SquareButton:* = null;    public static var LinkButton:* = null;    public static var LightButton:* = null;    public static var ComboBox:* = null;    public static var ListBox:* = null;    public static var Box:* = null;    public static var CheckBox:* = null;    public static var RadioButtonsGroup:* = null;    public static var Pagination:* = null;    public static var InputField:* = null;    public static var ScrollBar:* = null;    public static var Utils:* = null;*/    public static const LINK_BUTTON:uint = 0;    public static const BLUE_BUTTON:uint = 1;    public static const GRAY_BUTTON:uint = 2;        // ------------------------------------------------------------------------------ Creation wrappers.    public static function createMainMenu( wrapper:*, lazyMode:Boolean = false ):*    {      return new MainMenu( wrapper, lazyMode );    }        public static function createRoundButton( label:String, x:int, y:int, type:uint = 1 ):*    {      return new RoundButton( label, x, y, type );    }        public static function createSquareButton( label:String, x:int, y:int, type:uint = 1 ):*    {      return new SquareButton( label, x, y, type );    }        public static function createLinkButton( label:String, x:int, y:int, font_size:uint = 11, width:uint = 0, height:uint = 0 ):*    {      return new LinkButton( label, x, y, font_size, width, height );    }        public static function createLightButton( label:String, x:int, y:int, width:uint,            color:int, active_color:int, text_color:uint, active_text_color:uint,             align:uint = 0, font_size:uint = 11, margins:uint = 4 ):*    {      return new LightButton( label, x, y, width, color, active_color, text_color, active_text_color, align, font_size, margins );    }        public static function createComboBox( wrapper:*, x:int, y:int, width:uint ):*    {      return new ComboBox( wrapper, x, y, width );    }      public static function createListBox( x:int, y:int, width:uint ):*    {      return new ListBox( x, y, width );    }      public static function createBox( title:String, content:*, y:int, width:uint, buttons:Array ):*    {      return new Box( title, content, y, width, buttons );    }      public static function createCheckBox( title:String, x:int, y:int ):*    {      return new CheckBox( title, x, y );    }       /* public static function createRadioButtonsGroup( x:int, y:int ):*    {      return new RadioButtonsGroup( x, y );    }*/        public static function createPagination( totalCount:uint, x:uint, y:uint, height:uint = 0, type:uint = 0, pagesVisible:uint = 2, elemsOnPage:uint = 10 ):*    {      return new Pagination( totalCount, x, y, height, type, pagesVisible, elemsOnPage );    }        public static function createInputField( x:uint, y:uint, width:uint, linesCount:uint = 1, editable:Boolean = true, border:Boolean = true ):*    {      return new InputField( x, y, width, linesCount, editable, border );    }     public static function createScrollBar( x:int, y:int, height:int ):*    {      return new ScrollBar( x, y, height );    }     public static function addText( s:String, x:int, y:int, text_color:uint = 0, text_format:uint = 0x0010, width:uint = 0, height:uint = 0, font_size:uint = 11 ):*    {      return Utils.addText( x, y, width, font_size, s, text_color, text_format, height );    }  }} 
Далее в папке vk должна быть папка gui с файлами. Эту папку можно найти в этом архиве http://vkontakte.ru/source/vk_gui-0.5.zip.

Ну вот вроде и все. Жду ваши замечания)
Ответить