PXParallelLoader // name + onLoadProgressEVENT

8 views
Skip to first unread message

Thomas Pujolle

unread,
Mar 4, 2011, 7:57:51 PM3/4/11
to pixlib
Hi there,

I tried to set up a PXParallelLoader in a command, with its name, to
fill it up, and to run it in another command, but I got an error
saying this item is already registered.

I can get the same error by setting it up and running it in the same
command, if I set the name once, I cannot launch it. Just setting a
name up block everything :(

Any idea?

Another thing, I cannot get to display the correct loading percent, I
get "-10", and 10 is the number of item in the PXParallelLoader.

Do you know some particular context where the ProgressEvent is just a
pain? I got one a few weeks ago, it just kept killing my application,
and everything got fine when I put this progressEvent out.

Thank you!

Mike

unread,
Mar 7, 2011, 6:38:06 AM3/7/11
to pixlib
HI Thomas,


Locator:

There is two ways for handling asset naming in Pixlib

1) Let Pixlib defines auto-generated unique names, ex:
loader.add(new PXGraphicLoader(), null, new URLRequest("picto.jpg"),
context);

2) Define explicit names by yourself for convenience, ex:
loader.add(new PXGraphicLoader(), "MyImage", new
URLRequest("sample.jpg"), context);

In you choose the second way you must unregister locator name by
releasing loader item once loaded, ex:
private function _onItemLoaded(event : PXLoaderCollectionEvent) : void
{
event.stopImmediatePropagation();

PXDebug.DEBUG("Item loaded " + event.currentLoader.name, this);

var oLoader : PXGraphicLoader = event.currentLoader as
PXGraphicLoader;
oLoader.release();
}

As as side-effect your content will be unloaded unless you store ( new
PXGraphicLoader(holder) ) or reparent loaded content before releasing.



Progress:


Event you must listen for in PXParallelLoader is
PXLoaderCollectionEvent.onItemLoadProgressEVENT.
PXLoaderCollection.onLoadProgressEVENT does not apply in this case to
check overall progress. Fow now You'll have to implement this by
yourself (by monitoring onLoadInitEVENT for each loaded item).

var loader1 : PXGraphicLoader = new PXGraphicLoader(this);
loader.addEventListener(PXLoaderCollectionEvent.onItemLoadProgressEVENT,
_onItemDedicatedProgress);// will trigger only for loader1

loader.add(loader1, "image1", new URLRequest("image1.jpg"),
PXLoaderContext.getInstance());
loader.add(new PXGraphicLoader(this), "image2", new
URLRequest("image2.jpg"), PXLoaderContext.getInstance());
loader.addEventListener(PXLoaderCollectionEvent.onItemLoadStartEVENT,
_onItemStart);
loader.addEventListener(PXLoaderCollectionEvent.onItemLoadProgressEVENT,
_onItemProgress);
loader.addEventListener(PXLoaderCollectionEvent.onLoadInitEVENT,
_onQueueLoaded);// will trigger for all loaders (loader1 included)
loader.addEventListener(PXLoaderCollectionEvent.onItemLoadInitEVENT,
_onItemLoaded);
loader.load();


private function _onItemStart(event : PXLoaderCollectionEvent) : void
{
event.stopImmediatePropagation();

PXDebug.DEBUG("_onItemStart", this);
}

private function _onItemDedicatedProgress(event :
PXLoaderCollectionEvent) : void
{
event.stopImmediatePropagation();

PXDebug.INFO("_onItemProgress.name " + event.currentLoader.name,
this);
PXDebug.INFO("_onItemProgress.percentLoaded " +
event.currentLoader.percentLoaded, this);
}

private function _onItemProgress(event : PXLoaderCollectionEvent) :
void
{
event.stopImmediatePropagation();

PXDebug.DEBUG("_onItemProgress.name " + event.currentLoader.name,
this);
PXDebug.DEBUG("_onItemProgress.percentLoaded " +
event.currentLoader.percentLoaded, this);
}

private function _onItemLoaded(event : PXLoaderCollectionEvent) : void
{
event.stopImmediatePropagation();

PXDebug.DEBUG("Item loaded " + event.currentLoader.name, this);
}

private function _onQueueLoaded(event : PXLoaderCollectionEvent) :
void
{
event.stopImmediatePropagation();

PXDebug.DEBUG("All is loaded", this);

Thomas Pujolle

unread,
Mar 7, 2011, 5:16:13 PM3/7/11
to pixlib
Hi there!

I'm trying this right now, with this code:
public class PixlibTests extends PXBaseDocument
{
private var _loader:PXParallelLoader;

public function PixlibTests()
{

}
override protected function onDocumentReady():void {
_loader = new PXParallelLoader();
//_loader.name = "myParallelLoader";
_loader.add(new PXGraphicLoader(),"photo1",new URLRequest("assets/
photo1.jpg"),PXLoaderContext.getInstance());
_loader.add(new PXGraphicLoader(),"photo2",new URLRequest("assets/
photo2.jpg"),PXLoaderContext.getInstance());


_loader.addEventListener(PXLoaderCollectionEvent.onItemLoadProgressEVENT,
_onItemProgress);

_loader.addEventListener(PXLoaderCollectionEvent.onItemLoadInitEVENT,
_onItemLoaded);
_loader.addEventListener(PXLoaderCollectionEvent.onLoadInitEVENT,
_onPriorityLoaded);
_loader.load();

}
private function _onItemProgress(evt:PXLoaderCollectionEvent):void {
trace("PixlibTest ::
_onItemProgress :"+evt.currentLoader.percentLoaded + " : name :
"+evt.currentLoader.name);
}
private function _onPriorityLoaded(evt:PXLoaderCollectionEvent):void
{
trace("PixlibTest :: allLoaded");
}
private function _onItemLoaded(evt:PXLoaderCollectionEvent):void {
trace("PixlibTest :: _onItemLoaded : name
"+evt.currentLoader.name);
}
}


For the locator:
If I uncomment the "name = .." for the PXParallelLoader I get an error
saying that the name used "myParallelLoader" is already taken, even if
I keep the evt.stopImmediatePropagation and the 2 lines comming after
in your first post.

Without the name, everything is fine!

How come?

Mike

unread,
Mar 8, 2011, 3:17:52 AM3/8/11
to pixlib
Hi Thomas,

There is indeed a problem with PXAbstractLoaderCollection.onInitialize
implementation.
I submitted a fix to the team.

Thanks for reporting.

Thomas Pujolle

unread,
Mar 8, 2011, 6:54:35 AM3/8/11
to pixlib
Sir, Thank you Sir.
Message has been deleted

Thomas Pujolle

unread,
Mar 9, 2011, 4:06:00 AM3/9/11
to pixlib
Is it like a big problem?
Will it take long to get fixed? :D

Laurent Deletelaere

unread,
Mar 9, 2011, 5:07:40 AM3/9/11
to pix...@googlegroups.com
Hi Thomas,

The bug is fixed into the last revision (rev 23).

Thank you for your feedback!

cheers,
Laurent

Le 9/03/11 10:06, Thomas Pujolle a �crit :

Reply all
Reply to author
Forward
0 new messages