Форум Flasher.ru

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

Universe 28.04.2011 18:08

ArgumentError: Error #2100
 
Добрый день. Пытаюсь загрузить картинки с фейсбука и наталкиваюсь на следующую ошибку
Код:

ArgumentError: Error #2100: Длина параметра ByteArray в Loader.loadBytes() должна быть более 0.
at flash.display::Loader/_loadBytes()
at flash.display::Loader/loadBytes()
at com.main::FriendPhoto/imageLoaded()

И что интересно, тот способ который я использую сработал когда я его использовал для загрузки собственной картинки(т.е. аватара пользователя, который запустил приложение), но вот когда я в цикле гружу фотки друзей - вылетает эта ошибка.
Вот код который я использую:
Код AS3:

package com.main
{
        import flash.display.*;
        import flash.events.*;
        import com.greensock.*;
 
        public class FriendsBar extends MovieClip
        {
                public static var ADD_FRIEND_CLICK:String = 'add_friend_click';
                private var friendPhoto_mc:Sprite;
                private var destinationX:Number = 0;
                private var startX:Number = 0;
                private var friendsAvatars_arr:Array = [];
 
                public function FriendsBar(friendsAvatars_arr:Array)
                {
                        this.friendsAvatars_arr = friendsAvatars_arr;
                        if (stage) init();
                        else addEventListener(Event.ADDED_TO_STAGE, init);
                }
 
                private function init(e:Event=null):void
                {
                        trace("FriendsBar Created");
                        trace("friendsAvatars_arr " + friendsAvatars_arr);
                        addFriends();
                        left_arrow.buttonMode = true;
                        right_arrow.buttonMode = true;
                        destinationX = friendsContainer.x;
                        startX = destinationX;
                        left_arrow.addEventListener(MouseEvent.CLICK, onClickLeft);
                        right_arrow.addEventListener(MouseEvent.CLICK, onClickRight);
 
                }
 
                private function addFriends():void
                {
                        for(var i:uint; i< friendsAvatars_arr.length; i++)
                        {
                                trace("AVATAR " + friendsAvatars_arr[i]);
                                friendPhoto_mc = new FriendPhoto(friendsAvatars_arr[i]);
                                friendPhoto_mc.x = (friendPhoto_mc.width - 16)* i - 5;
                                friendPhoto_mc.alpha = .7;
                                friendPhoto_mc.buttonMode = true;
                                friendPhoto_mc.addEventListener(MouseEvent.MOUSE_OVER, onOver);
                                friendPhoto_mc.addEventListener(MouseEvent.MOUSE_OUT, onOut);
                                friendPhoto_mc.addEventListener(MouseEvent.CLICK, onFriendPhotoClick);
                                friendsContainer.addChild(friendPhoto_mc);
                        }
                }
 
                private function onFriendPhotoClick(event:MouseEvent):void {
                        dispatchEvent(new Event(ADD_FRIEND_CLICK));       
                }
 
 
                private function onOver(e:MouseEvent):void
                {
                        TweenLite.to(e.currentTarget, 0.5, {alpha:1});
                }
 
                private function onOut(e:MouseEvent):void
                {
                        TweenLite.to(e.currentTarget, 0.5, {alpha:.7});
                }
 
                private function onClickLeft(e:MouseEvent):void
                {
                        if(destinationX < startX - 5)
                        {
                                destinationX += friendPhoto_mc.width-16;
                                trace("Left " + destinationX);
                                TweenLite.to(friendsContainer, 0.5, {x:destinationX});
                        }
                }
 
                private function onClickRight(e:MouseEvent):void
                {
                        if(destinationX > -friendsContainer.width / 2+friendPhoto_mc.width)
                        {
                                destinationX -= friendPhoto_mc.width-16;
                                trace("Right " + destinationX, startX);
                                TweenLite.to(friendsContainer, 0.5, {x:destinationX});
                        }
                }
        }
}

Класс FriendPhoto
Код AS3:

package com.main
{
        import flash.display.*;
        import flash.events.*;
        import flash.utils.*;
        import flash.net.*;
        import flash.text.*;
        import flash.system.*;
 
        public class FriendPhoto extends MovieClip
        {
                private var userPath:String = "";
                private var imgLoader:Loader;
                private var context:LoaderContext;
 
                public function FriendPhoto(userPath:String)
                {
                        trace("FRIEND ADDED");
                        this.userPath = userPath;
                        if (stage) init();
                        else addEventListener(Event.ADDED_TO_STAGE, init);
                }
 
                private function init(e:Event = null):void
                {
                        trace("UserPhoto Created");
                        result_txt.text = userPath;
                        loadImage();
                }
 
                private function loadImage():void
                {
                        imgLoader = new Loader();
                        context = new LoaderContext();
                        context.checkPolicyFile = true;
                        imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
                        imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading);
                        imgLoader.load(new URLRequest(userPath), context);
                }
 
                private function imageLoading(e:ProgressEvent):void
                {
                        preloader.scaleX = e.bytesLoaded/e.bytesTotal;
                }
 
                private function imageLoaded(e:Event):void
                {
                        //trace(imgLoader.getChildAt(0));
                        trace("FRIEND IMAGE LOADED");
                        imgLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, imageLoaded);
                        //imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, handler_complete);
                        trace("BYTES " + imgLoader.loadBytes(this.imgLoader.contentLoaderInfo.bytes, new LoaderContext(false, ApplicationDomain.currentDomain)));
                        //imgLoader.loadBytes(this.imgLoader.contentLoaderInfo.bytes, new LoaderContext(false, ApplicationDomain.currentDomain));
                }
 
                private function handler_complete(e:Event):void
                {
                        var bmd:BitmapData = new BitmapData(imgLoader.width, imgLoader.height, true);
                        bmd.draw (imgLoader);
                        var img:Bitmap = new Bitmap(bmd);
                        img.smoothing = true;
                        img.mask = mask_mc;
                        img.x = mask_mc.x;
                        img.y = mask_mc.y;
                        resizeImage(img, mask_mc);
 
                        addChild(img);
 
                        //result_txt.text = userPath + "LOADED";
                        trace("Some actions with the image!");
                        preloader.visible = false;
                }
 
                private function resizeImage(img:Bitmap, mask_mc:MovieClip):void
                {
                        var imgRatio:Number = img.height/img.width;
                        img.width = mask_mc.width;
                        img.height = mask_mc.width * imgRatio;
                }
        }
}

В чём может быть ошибка?

cleptoman 28.04.2011 20:03

контексты попробуйте поубирать

Universe 12.05.2011 18:52

не помогло, всё равно пишет что Длина параметра ByteArray в Loader.loadBytes() должна быть более 0. Т.е. получается что он ничего не грузит?! Что странно - если я просто вбиваю url картинки друга в строку адреса - браузер мне её показывает! В чём же проблема?


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

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