Cocos2dx - How to load resources in loading scene between scenes - cocos2d-x

I want to load resources in loading scene between scenes. I read they suggest preLoad but I have no idea to use it. Can you explain for me how it works?
Can you give me some detail example? Thanks

You can create a loading scene and load Images asynchronously using CCTextureCache::sharedTextureCache()->addImageAsync(...) method. It will add all images to shared texture chache. Whenever you create any Sprite or Texture it looks for key in CCTextureCache if there already a key exist then it will not load image again.
Alternatively you can remove textures from TextureCache using specific key name or all texture or unused ones.
Check API Here :
http://www.cocos2d-x.org/reference/native-cpp/V2.2.2/dd/d27/classcocos2d_1_1_c_c_texture_cache.html#a4397d1be3c0043536fdd32f55a54f747

After a long time of study i found that you can do that using:
Sequence Action
I got it working now in v-3x.

Related

Libgdx + Glide - Couldn't load dependencies of asset

Unlike all the issues involving this error, this one is a bit tricky.
I have the following:
Downloading a .png image with Glide v3 into my app's internal storage, using SimpleTarget to get a bitmap and saving it into a file.
I know by fact that this sometimes is saving a corrupted file, maybe due timeout issues.
This is ok.
The problem comes when libgdx's AssetManager tries to render this file.
It throws the "Couldn't load dependencies of asset" error.
Which is ok.
So, what I need to know is:
Is there any way to catch that error getting the file name to delete it and start a new download call?
What I tried to do already:
Looking for AssetManager functions to check the files integrity, theres none as far as I could check
Checking the file with FileHandleResolver and Gdx.files.absolute(fileName).exists, but this is usesless because the file indeed exists and its size isnt 0.
Catching the GdxRuntimeException, parsing it to get the file name, but this is kinda the worst way.
Thank you guys in advance.
You can add an AssetErrorListener to your AssetManager. This will give you the AssetDescriptor for the particular asset which failed to load as well as the associated exception. Those two pieces of information should allow you to get what you need to redownload and retry.

Issue loading external swf on main file with as3

Hi I'm new to Flash CS6 and and AS3 and I have been stuck on this iPad/Android restaurant menu I have been doing. I amm trying to load an external swf on my main swf but have been getting this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at cuisine/init()[C:\Users\PAO\Desktop\OZ\SWIPE\cuisine.as:32]
at cuisine()[C:\Users\PAO\Desktop\OZ\SWIPE\cuisine.as:22]
I got the code of the swipes from a tutorial I found online. in the different sections fo the menu I was planning to load different swfs because I couldn't get the code to work for all the sections at the same time.
like I said, I am new to as3 and I really don't understand all the coding so i'm really stuck at a dead end.
hoping a kind soul could help me get out of this rut. the files can be found here
It can be a bit unintuitive to load external SWFs, especially if you are new to AS3. If I remember correctly, a big problem can be that you need to wait for the ENTIRE swf to load before trying to access anything.
You should only try to access code from the external swf after the Event.COMPLETE event. see here for more info
I would also suggest use the Greensock loader instead since it's a bit simpler.
Hope that helps

Main menu on game

I have created a menu for my game with buttons and whatnot as a separate .fla file named Menu. My actual game is another .fla file called Game.fla. I was wondering what the best way would be of loading this menu before the game plays?
Thanks.
I would suggest that you create a .swc with your Menu.fla, and then just add that .swc to your Game.fla
If you are using CS6, make sure that you are setting linkage for any MovieClips you want to create instances of in your code.
In the actionscript settings on the library path tab, you can add a .swc that will be included into your .swf when compiling.
In your code, you can now create an instance and add to the display list :
// Assuming MainMenu was a movieclip with linkage set in your .swc
var mainMenu:MainMenu = new MainMenu;
addChild(mainMenu);
I should note that this does not load the .swc at runtime, it includes the .swc to your .swf at compile time. I would recommend this method over loading a .swf in most cases. Cases where I might not, is if there was a large amount of content that wasn't needed all at once. That would allow you to minimize the amount of memory you were using and reduce the .swf size of your main .swf so it loads quicker.
Anytime you are loading .swf's in at runtime you are adding another layer of complexity, so I'd not recommend it unless you do have a good reason to do so. From what you have described, this doesn't sound like a situation where I'd load an external .swf at runtime.
Load the swf output from Menu.fla and keep a check on the progressEvent from loader. Don't show the game screen until Menu.swf is completely loaded and initialized.
Some more details wrt comment from OP:
You can you http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#load%28%29 to load external swfs. init Event would mark that the swf's actionscript has started executing. OTOH, complete event would tell that all the swf bytes have been loaded.

Pass file from AS3 into embedded AS2 wrapper to load

I have a Flash AS3 application that uses FileReference.browse() to request a SWF from the user. If the chosen SWF is AS3, I'm good to go. However, if it's AS2, I need to load it into an AS2 wrapper first (so my app can alter it). All of these files (including my app and wrapper) are intended to exist locally on the user's machine, but the file they select can exist in any directory. So to be clear: Main application (AS3) -> Wrapper (AS2) -> User's file (AS2)
I know how to get the uploaded file's ActionScript version from the Loader's loaderInfo.actionScriptVersion variable, and that's working correctly. My issue is how to pass the file from the AS3 application to the AS2 wrapper so it can load it.
My first thought was to dump the ByteArray from the FileReference's load() function into a SharedObject "cookie". This method seemed pretty bad from a user-experience point of view, but it seemed most likely to work. However, I've been unable to find any method within AS2 to load the ByteArray as a movie (in fact, AS2 doesn't even seem to have a ByteArray class). So the first potential solution to my problem would be if anyone knew of a method for loading a movie from a ByteArray in AS2.
My second thought was to pass the uploaded file's path to my wrapper via the already-setup LocalConnection bridge, and then just have it load the file from that. However, I can't find any way to get the file's path, and my Googling suggests the security model intentionally prevents it. Not to mention, I'm not sure I can load an arbitrary file from the user's machine.
My "hands up in the air; I give up" solution was to just create separate buttons for loading AS3 and AS2 files (leaving it up to the users to guess which it is!) and have the AS2 button actually within the AS2 wrapper. However, it looks like AS2 doesn't have a file browsing uploading API, and the PHP-hybrid solutions I've found aren't an option (because this is meant to be run locally).
So, I would be eternally grateful if anyone could point me in the right direction for solving any of these three roadblocks. Alternative workarounds are of course welcome.
(Edit)
Ok, I found the documentation for AS2's version of the FileReference class. It supports the same file-browsing capability, but does not support directly loading the selected file into the SWF.
However, the security sandbox doesn't seem as strict for local files as I expected, and it looks like I can load any SWF on the user's machine once I have a path to it. So I should be able use JavaScript and an HTML form with a file input to get and pass the file path to my application. It's not ideal having to do all of this from within a web browser, but it should work. If it turns out satisfactorily I'll submit it as an answer.
(Edit 2)
Scratch the HTML-form idea. Looks like the path is hidden from JavaScript for the same reasons Flash hides it. The only option I can think of now is to have the user copy and paste the path to the file...
After reading over your post, you may be able to retry one of your previous attemps with some new information. Actionscript 2 DOES have a method for looking up files from a browser, same as AS3 does. AS2 also has a FileReference class. Check out the documentation here:
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001040.html
Also, here is a tutorial:
http://markshu.ca/imm/flash/tutorial/fileReference.html
Well, all of my other leads have dried up, so I'm submitting the two answers that will actually work, although neither is ideal:
A) Use Adobe AIR, which will give more access to the filesystem (such as for getting path info) at the cost of requiring the separate AIR runtime to be installed.
B) Have the user enter the path to the file themselves (cumbersome for the user)

AS3: How to dynamically load movieclip from library without exporting in frame 1?

I have some fairly large movieclips in the library which need to be dynamically loaded at runtime. I don't want to export them all in frame 1, because that would slow down initial loading of the movie.
I tried putting an instance of each of these clips later in the timeline where they wouldn't normally be encountered. When I then tried to load one from the library dynamically, I was able to successfully get an instance of the movieclip, but its currentFrame property was 0 and I couldn't see anything on the stage. As soon as I enabled "Export in frame 1", it worked properly.
Does this old trick of putting an instance on the timeline somewhere no longer work in AS3?
I have had similar issues with large library assets and to solve my issue I would always just put the assets into separate swf's and load the external swf file when I needed it.
Check out the Loader class 'content' property - http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html#content
The only downfall to this is managing the assets in separate files.
I hope this helps.