How to do transition to next frame - actionscript-3

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.

Related

activating a function of a parent as3

I'm attempting to set up a saving and loading system for a flash game I am creating. At the moment I decided to attempt to get the Save File Selection part of my new game menu to work before I proceeded any further with it. I drew up the 'DifficultySelect' screen (which contains save file selection as well as a few other things) in flash, then converted it into a symbol. I made 10 save file symbols inside of this, and created base actionscript files for them. The entire 'DifficultySelect' becomes a child of my 'Main.as' once you proceed through the title screen. I am trying to have my save file data inside of my Main.as, such as levels, health, progress, etc, as well as which save file is currently in use. However, I am unable to create a way for my Main.as to access a MouseClick function for the save file, as I can't simply have a Savefile0.MouseEvent.CLICK event in my Main.as file, as I am not creating a variable to add it to the stage.
I suppose the tl;dr question version of my situation is: How can I get my Main.as to activate one of its functions when SaveFile0 has been clicked? Also, how do I refer to a child from a parent class?
You ask how to refer to a child from parent, but since the child usually "knows" its parent, I suggest following solution:
Your child (SaveFile) should listen for the event (MouseEvent). Once the event is dispatched, you have two options. Either you can dispatch a custom event on parent or directly invoke a public function of the parent.
This is assuming your SaveFile is a MovieClip added to Main:
Inside SaveFile:
var _parentMC:MovieClip = this.parent as MovieClip;
_parentMC.functionToCall();
The best practice, however is to dispatch a custom event in SaveFile, and listen for it in main:
Inside SaveFile:
var customEvent:Event = new Event("customEvent");
this.dispatchEvent(customEvent);
Inside Main:
saveFile.addEventListener("customEvent",functionToCall();
functionToCall(e:Event):void{
}

What is the best way to access/reference a dynamically generated object that has linkage in the stage?

In actionscript 3, what is the best way to access/reference a dynamically generated object that has linkage in the stage which is the type of Movie Clip, where the dynamically placed object(s) are located in the specific frame (one keyframe) and accessed via custom function from timeline code in a long frame?
And also, what is the appropriate code to remove child/object that are dynamically placed Object/CLass name (which is being extended from library) from the stage (main timeline)?

I need to remove a loaded swf file loaded by a different swf file

I have an swf file (swf2) that loads into my main swf file (swf1). On the click of a button (which is housed in the loaded swf file swf2) I need to stop swf2 from running and load on new swf (swf3).
I am using removeChild(loader);
But the problem is loader in in the parent (swf1) swf, how do I reference it?
Sorry if this is not enough info, I am not really an expert here.
Thanks
The way I understand this is that you have swf1 loading swf2. Swf2 contains a button that when pressed, causes swf1 to unload swf2 and load swf3.
There are a few ways to do communicate between loaded swfs and their parents. One way (the method I usually use depending on context) is that you could have the loaded swf throw an event that the parent can listen to and catch. In this case, your loaded swf2 could throw a "close" event the parent swf1can catch and then use to trigger the unloading of the swf2 (and load the swf3).
For another way, check to see if you can access the parent (which would be the main loading swf, swf1) inside the loaded child swf by it's parent property. I can't always recommend this though as it can be unclear to what 'parent' may refer to in the future if you reuse swf2 with another loader.
Something else to consider though, if this button is meant to control loading and unloading of children swfs, would it make more sense to move it out to the loader itself since that is where the behaviour is? This would also eliminate the problem.

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.

How can I use SWFLoader purely from Actionscript in Flex 3 and dynamically load content?

I'm doing a Flex 3 project wherein I've to load SWF based on the availability of required file. And the loaded SWF file will be placed in a container (a Panel) at a particular location i.e. coordinates. This I don't want to do in MXML as the SWFLoader container shows a cross marked box if the file is unavailable.
So friends is there any solution?
Create a new URLRequest object with the url of the file.
Create a new Loader object.
Call the Loader object's load() method, passing the URLRequest instance as a parameter.
Call the addChild() method on a display object container (such as the main timeline of a Flash document) to add the Loader instance to the display list.
Source: Loading an external SWF file.