How to change an image inside a Movieclip, from an external asset? - actionscript-3

I have 2 SWF files.
One is for assets and contains some PNG files (which is actually a skin for my application), which exported to ActionScript.
The second one is for the main application, which loads the first SWF (using Loader) and uses its PNG files (using getClassDefinition to get the files).
I'm having some movieclips and buttons on the stage, which contains for than one simple frame (for example; a mute button, which has the "playing" state and "muted" state in 2 different frames of the mute's movieclip).
When I'm changing the images in the frames and then call gotoAndStop (to move to another frame inside to movieclip), the images returns to the originals.
Also, I have no idea how to swap the images inside the buttons.
Notice that I don't want to load an external movieclip (from the first SWF), but just PNGs.
Any idea?

Related

Frame by Frame animation AS3

This is for AS3 FlashDevelop, Basically I'm super new to this. The most I've done in AS3 coding is display multiple images on a single frame and parallax images.
However I want to know how to display embedded Bitmap (.png pictures) as frames one after another,
like frame 1 = embedded image 1 frame 2 = embedded image 2 (frame 1 is gone but 2 shows) frame 3 = embedded image 3 (and so on.)
and they would continuously play as an animation and stop at the first frame until I press play again
I believe I would use nextFrame, stop and gotoframe but don't know where and what I need to code, I heard of bitmapdata but I'm stuck on how to use it in purpose of animating frame by frame.
EDIT: No I'm not animating sprites, rather it's more like cartoon process where you'll go frame by frame of the image files, as one appear the previous one disappears.
You could iterate through each frame and add the images after you load them.
If you do addChild() it should add it to the current frame you're on. Load the next image with a Loader, place it down with addChild, nextFrame(), and repeat until you have all the images. Then when they're all loaded (from what I guess would be some list you'd have in an array or an xml) take the user to frame 1. You might want to do this inside of a movieclip while having that and a cover graphic on your main stage so the user doesn't see all of the images while they're being loaded and placed.
[More about adding display objects to frames]

How to do transition to next frame

I'm a beginner in AS3 and Flash.
There are index.swf and intro.swf, which is loaded in first frame of index file.
In intro.swf I placed a button, which should send command to index.swf main timeline to go to frame 2.
If i use parent's construction, i will try to access level that is not present in intro file at the moment of compilation. So, how can I do it?
First of all you should define which method you use to load one swf to another. On this depends what will be the reference to the top level.
If you used flash.display.Loader then from MainTimeline of loaded swf to MainTimeline of loader swf (if you load not inside so object but create Loader itself by code on Maintimeline - reference will be
MovieClip(parent.parent)
Loaded swf root stored inside Loader instance at content property, that why there is two parent. And data-type convertion should used because parent return reference as DisplayObject and thats block you from access it properties.

How do i get my UILoader to play an .SWF once then disappear?

How do i get my UILoader to play a .swf file once then disappear until called upon again?
I am creating a guitar tutorial app that shows you chords and the transitions between them. to display the chords I'm using standard Flash graphics and for the transitions i am using a UI Loader to display the .swf files for instance, on the C chord frame, the fingers are in position and the UI Loader is a layer on top of it, when the chord transition is selected from the list component it loads the chordtransition.swf.
The problem is that once the swf is loaded it plays on loop, ive added "stop();" in many different places as people suggest and it doesn't make a difference.
I would like to be able to click "C-D" on the component list then for the .swf to play once then disappear.
Any ideas??
A strategically placed stop() should work (last frame on the timeline in the swf). You'll need to stop the right movieclip - if your movie has nested clips you might be stopping the wrong clip.
However, creating multiple swf's just to show different chords looks like overkill to me.
Create clips showing all chords on the main timeline, and add frame labels to indicate where they start and put stop() at the end of every chord animation (are you using animations?).
Use movieclipWithChords.gotoAndPlay("chord_C");
If you are not using animations you can use movieclipWithChords.gotoAndStop("chord_C");
Of course you can also create labels like 'C' and 'D', and use those as a direct mapping of the chords.
Update: After reading your question again I realize you are actually showing clips of a transition from one chord to another. In that case you can still use my suggestion as above, only your labels will not be for the individual chords, but for the chord transitions e.g. 'transition_C-D' or 'transition_G-B'.

Only the loader images are being exported in frame 1 but the loader still only shows up at 100%

As the title says, the file loads correctly but the loading screen only flashes up at the end.
The only thing being exported in frame 1 is the loader image, and that is extremely small.
Is it possible that there's a queue of things being loaded and the loader image is at the bottom of that queue? Since that was one of the last things added to the project
If your preloader only shows up after the file has loaded, this means that you still have other objects being linked onto Frame 1. Flash is very picky about this, and it's easy for things to be yanked onto Frame 1 regardless of your settings. When you compile, Flash builds a dependency graph to determine what items are needed on each frame. If it thinks an asset is needed earlier than the export frame setting, it will ignore the setting and push the asset onto that frame. In particular, any class that your document class directly references will be automatically yanked onto frame 1.
Checking "Generate size report" in File, Publish Settings, Flash can help you see how much data is being exported onto Frame 1. Here are some tips to ensure that everything is linked onto the proper frame:
In Publish Settings, Flash, ActionScript Settings, make sure that "Export frame for classes" is set to 2 or higher.
Ensure that library symbols say "Export on frame 2" in their linkage properties. Older versions of Flash may export them on frame 1, regardless of the class export frame. In this case, you'll have to do the oldschool method of unchecking the "Export on frame 1" option, and manually dragging these symbols onto the timeline on frame 2.
Do not directly reference classes from your document class or on the main timeline. The Document class and all the assets it references are always placed on frame 1. Anytime you do var f : MyClass; in your document class or on the root timeline, then you are referencing MyClass, and Flash will automatically yank it onto frame 1.
To avoid directly referencing your main app class in your preloader, you want to instantiate it indirectly, using something like this:
var gameClass : Class = flash.utils.getDefinitionByName("Game") as Class;
var game : Sprite = new gameClass();
In this case, your Preloader becomes the document class, and indirectly creates the Game class when the SWF has loaded. This avoids any direct references to Game and its content.

Load SWF data without loading sound, then load sound later

So, hypothetical situation here:
I have an SWF that's 30MB. Sound files (music) make up 25MB, art and other things make up the remaining 5MB.
Would it be possible for me to load the 5MB of necessary art and other things first to allow the user to operate the app, then after that's all loaded and they are operating the app, load the remaining 25MB of sound files in the background?
UPDATE:
Loading SWF (or other entities) externally is not an option.
You can do this by modifying the compilation settings and strategically placing the sound.
By default, anything placed on the timeline will be loaded sequentially; the Flash Player will play the SWF as soon as the first frame is loaded. If you use the default compilation settings, all library content will be placed in the first frame, so the movie doesn't start until everything is available.
You can modify these settings, however, to allow for a more sequential load order: For each of your library elements, you can uncheck "export into frame 1" in the properties window. Now these elements won't be loaded, until they appear in the main timeline. This way, if you place your content carefully, you can allow for all important elements to be loaded in the first frame, or if you have a progress bar, until the main movie starts, while all streaming elements load with the animation, which has to be placed accordingly. Make sure though, that you don't leave anything out (by not placing it on the timeline), or call elements from ActionScript before they are loaded completely. It is very important to test this thoroughly, because if anything goes wrong in the load order, your entire SWF might stop working.
Also, remember that the SWF loads sequentially: If you have a sound in, say, frame 300, and another in frame 1000, the one in 300 will be loaded first. If you jump to frame 1000 from a menu in frame 10, you have to take into account that the frame might not be loaded yet. So there has to be some sort of checking mechanism (framesLoaded) and/or dialog to inform the user about additional loading time, and prevent the application from crashing.