Re: Помогите с кодом вывода друзей!
Добавлено: 04 авг 2012, 12:58
А вот этот код должен работать нормально:
Код: Выделить всё
var quantity:int = 0; var arr:Array = [];var friends:Array = [];var index:int = 0; vkBase.API('execute', {code:'return API.users.get({uids:API.friends.getAppUsers(),fields:"photo"});'}, loadFriends, printError); function loadFriends(response:Array):void{ if (response.length) { quantity = response.length > 6 ? 6 : response.length; for (var i:int = 0; i < quantity; i++) { arr.push([new Loader, new TextField]); arr[i][0].x = arr[i][1].x = 65 + 115 * i; arr[i][0].y = (arr[i][1].y = 575) - 50; arr[i][0].addEventListener(MouseEvent.CLICK, onClick); addChild(arr[i][0]); addChild(arr[i][1]); } friends = response; initFriends(); }} function printError(error:Object):void{ var tf:TextField = new TextField(); tf.x = 100; tf.y = 100; tf.width = 300; tf.height = 300; tf.text = error.error_msg; while (numChildren) removeChildAt(numChildren - 1); addChild(tf);} function onClick(e:MouseEvent):void{ navigateToURL(new URLRequest('http://vk.com/id' + friends[index + (e.target.x - 65) / 115].uid), '_blank');} function initFriends():void{ if (index < 0) index = 0; else if (index + quantity - 1 > friends.length) index = friends.length - quantity - 1; for (var i:int = 0; i < quantity; i++) { arr[i][0].load(new URLRequest(friends[index + i].photo)); arr[i][1].text = friends[index + i].first_name; }} function toLeft(e:* = null):void //перелистывание влево{ index -= quantity - 1; initFriends();} function toRight(e:* = null):void // перелистывание вправо{ index += quantity - 1; initFriends();}