Jump to content
Search Community

Dooprod

Members
  • Posts

    6
  • Joined

  • Last visited

Dooprod's Achievements

  1. Hi! Yep I think I should started with sources! So here something you can download: Exemple Sources Run it in debug mode -> everything is explain in the console ( some comments to help ). Thanks again for your time and your help!
  2. Thanks again for your time! Yes, the main problem I have, it's to get content / loader outside the "Complete" event function ( based on LoaderEvent ). // Init the XML public function init() { xmlLoader = new XMLLoader( "PathToXml", { onComplete:xmlComplete } ); } // XML Complete -> Now load a LoaderMax that is inside this XML private function xmlComplete( e:LoaderEvent ):void { loaderMax = LoaderMax.getLoader( "LoaderID" ); loaderMax.addEventListener( LoaderEvent.COMPLETE, loaderComplete ); loaderMax.load(); } // LoaderMax Complete -> Get content inside this Loader private function loaderComplete( e:LoaderEvent ):void { dispatchEvent( new Event( "LoaderComplete", true, true ); trace( loaderMax.getContent( "ContentID" ) ); // return an object - OK trace( loaderMax.getContent( "AnotherID" ) ); // return another object - OK } // A public function to get content inside the LoaderMax public function getContent( contentID:String ):void { trace( loaderMax.getContent( contentID ) ); // return null / error } So if I put this code in a new class, let say "AssetLoader.as", I can add this everywhere in my game ( assetLoader = new AssetLoader(); ), and when I want a specific content, I just call the "getContent" function ( assetLoader.getContent( "contentID" ), that should return an object I can use... But right now, this function return nothing! Of course, I know that I have to wait until the loading is complete, that's why I dispatch the "LoaderComplete" event. With that I know when the content is loaded and available, but just "how I can acces this content" now from external class! I hope it will help! Thanks again!
  3. Hello! And thanks for your time! Sorry for the "pseudo code", I wrote that very quickly, and I don't even realize that I left errors! So yes, the idea is to create a kind of asset manager. A class that create and display a loading screen (with a progress bar), and behind load everything we need through XML and some methods I can call to get assets on my scene. Right now, I repeat the loading stuff in every class (eg: level 1, 2, 3...). You can have a look of this in this video. First I have the "Main Menu" class, when I touch "Play", the main menu fade out, and the "Select World" class, first with the loading screen (which is inside this class) and when it's complete, display the scene: http://youtu.be/yokcjv69JtY?t=38s package { public class Level1 { public function Level1() { // Load XML -- xmlLoader = new XMLLoader ( "PathToTheXML", { onComplete:loadStuff } ); } private function loadStuff( e:LoaderEvent ):void { // ProgressBar -- progressBar = new Sprite(); addChild( progressBar ); // LoaderMax -- loaderMax = LoaderMax.getLoader( "loaderID" ); loaderMax.addEventListener( LoaderEvent.PROGRESS, loaderProgress ); loaderMax.addEventListener( LoaderEvent.COMPLETE, loaderComplete ); loaderMax.load(); } private function loaderProgress( e:LoaderEvent ):void { progressBar.scaleX = e.target.progress; } private function loaderComplete( e:LoaderEvent ):void { // Clean screen -- removeChild( progressBar ); // Load stuff -- texture1 = TextureFromBitmapData( LoaderMax.getLoader( "contentID-1" ) ); texture2 = TextureFromBitmapData( LoaderMax.getLoader( "contentID-2" ) ); // Display object on the scene -- sprite1 = new Sprite( texture1 ); addChild( sprite1 ); } } Not very handy because if I made a change on the loader, I have to open every class, that's why I want to create a specitif "LoaderScreen". A screen that I can add on top of the scene I want to load, then when to everything is loaded I can call what I need ( images, textures, sounds... ). So, the main application should looks like this: So first, I create the LoaderScreen class: package { public function LoaderScreen() { xmlLoader = new XMLLoader ( "PathToTheXML", { onComplete:loadStuff } ); } private function loadStuff( e:LoaderEvent ):void { // ProgressBar -- progressBar = new Sprite(); addChild( progressBar ); // LoaderMax -- loaderMax = LoaderMax.getLoader( "loaderID" ); loaderMax.addEventListener( LoaderEvent.PROGRESS, loaderProgress ); loaderMax.addEventListener( LoaderEvent.COMPLETE, loaderComplete ); loaderMax.load(); } private function loaderProgress( e:LoaderEvent ):void { progressBar.scaleX = e.target.progress; } private function loaderComplete( e:LoaderEvent:void { dispatchEvent( new Event( "LoaderComplete", true, true ) ); } // HELPERS -- // Call from everywhere to get asset public function getAssetIMG( idAsset:String ):BitmapData { // Return bitmapdata return LoaderMax.getLoader( idAsset ).rawContent.bitmapData; } public function getAssetATF( idAsset:String ):ByteArray { // Return bytearray return LoaderMax.getContent( idAsset ); } } Now I can create scenes where I can call the LoaderScreen. The LoaderScreen will be on top of the scene. So it will display the progress bar, and when it completes, I can remove the LoaderScreen, to see the scene behind: package { public class Level1 { public function Level1() { // Create a LoaderScreen to on top of this scene loaderScreen = new LoaderScreen(); guiLayer.addChild( loaderScreen ); // I create an EventListener, waiting for the "Complete Event" of the LoaderScreen loaderScreen.addEventListener( "LoaderComplete", initScene ); } private function initScene():void { // Load stuff through the "getAsset" function -- texture1 = TextureFromBitmapData( loaderScreen.getAssetIMG( "ID1" ) ); texture2 = TextureFromBitmapData( loaderScreen.getAssetIMG( "ID2" ) ); texture3 = TextureFromATF( loaderScreen.getAssetATF( "ID3" ) ); // Display Object -- sprite1 = new Sprite( texture1 ); addChild( sprite1 ); // Init scene complete -- guiLayer.removeChild( loaderScreen ); // Now I can see the scene -- } } I hop it's a little bit more clean now. I have my own AssetManager, but I wanted to use GSAP to be more flexible ( can animate the loader / create a TimelineMax for fade In / Out the scene... etc... ). But right now, when I try to call object outside the function loaderProgress( e:LoaderEvent ), it returns an error / null. Thanks again for your time!
  4. Hello! Is it possible to load objects outside the "complete" events ( LoaderEvent )? Right now, it's like this: function initLoader():void { xmlLoader = new XMLLoader( "PathToXml/xml.xml", { onComplete:loadData } ); xmlLoader.load(); } function loadData( e:LoaderEvent ):void { loaderMax = LoaderMax.getLoader( "loaderID" ); loaderMax.addEventListener( LoaderEvent.COMPLETE, completeLoader ); loaderMax.load(); } function completeLoader( e:LoaderMax ):void { texture1 = TextureFromBitmapData( LoaderMax.getLoader( "image1" ).rawContent.bitmapData ); texture2 = TextureFromBitmapData( LoaderMax.getLoader( "image2" ).rawContent.bitmapData ); texture3 = TextureFromBitmapData( LoaderMax.getLoader( "image3" ).rawContent.bitmapData ); (...) } And it works, but I have to write this in every class of my app, not handy if I have to change something... That's why I wanted to create a "LoaderScreen" class, that I call where I need, with some methods to help me to handle all the assets / loaders. More or less like this: class LoaderScreen public function LoaderScreen( loaderId:String ) { xmlLoader = new XMLLoader( "xml", { onComplete:loadData } ); xmlLoader.load(); } private function loadData( e:LoaderEvent ):void { loaderMax = LoaderMax.getLoader( loaderID ); loaderMax.addEventListener( LoaderEvent.COMPLETE, completeLoader ); loaderMax.load(); } private function completeLoader( e:LoaderEvent ):void { // nothing here } // HELPERS -- public function loadBitmapdata( id:String ):BitmapData { return mainLoader.getLoader( "texParticleMenuHome" ).rawContent.bitmapData; } And now I want to create a LoaderScreen object, and try to load stuff: class Anywhere public class Anywhere() { var loaderScreen:LoaderScreen = new LoaderScreen( "myID" ); addChild( loaderScreen ); texture1 = TextureFromBitmapData( loaderScreen.loadImage( "image1" ) ); texture2 = TextureFromBitmapData( loaderScreen.loadImage( "image2" ) ); texture3 = TextureFromBitmapData( loaderScreen.loadImage( "image3" ) ); } But it returns "null" when I'm not in the "complete" event handler ( LoaderEvent ). trace( mainLoader.getLoader( "xxx" ) ) in the complete event return something trace( mainLoader.getLoader( "xxx" ) ) outside, return null It's a kind of "AssetsManager" I guess ( based on my framework ) but I only need to know how I can load stuff outside the LoaderEvent. If anyone can help me, or have a suggestion...! Thanks!
  5. Thanks! I just wanted to write something here, because FB 4.7 is now live(beta), and I think a lots of people will find this same error! But v12 is already here too...! Just matter of time to completly switch!
  6. Hi everyone! I'm just here to talk about a small error I found when I use Flash Builder 4.7 (beta), with Air3.4 SDK. With the new ASC2 (more infos here: http://www.bytearray.org/?p=4789), the "goto" ref is now not allow. So in the file "TimelineLite.as" by exemple, this function will return an error : public function goto(timeOrLabel:*, suppressEvents:Boolean=true):void { setTotalTime(parseTimeOrLabel(timeOrLabel), suppressEvents); } So, you can comment this line (if you don't use goTo of course...), and it will work. Maybe we can have more information on this for the futur? Just said that for the next v12 of Greensock Plateform! Thanks!
×
×
  • Create New...