How to make flash builder component affect main application? - actionscript-3

I have my main application, which contains several instances of a component that create a grid of photos belonging to a certain category. (the grids, and the photos are created dynamically with a loop).
I'd like to be able to click a photo to run a function that loads the large version of the photo into a separate element that is contained in the main application. So I created a Photo component in my main application, but how, using actionscript, do I change the 'currentphoto' variable in my main application from inside the tileview component?
Alternately I could put the function in the main application (probably more logical in the long run), but how would I call it from the child component?

I would dispatch a Event.SELECT event in the tileview when a photo is selected that the main application adds an event listener for. The tileview should have a selectedImage property or something similar so that the main app can determine what image to load in the photo component when it receives an event.

Related

How can I destroy a widget component in ue4 blueprints?

I have a question regarding UE4 widget objects in blueprints. I try to spawn new widget objects at runtime and add them to a unit. Then I want to play a simple animation and destroy the created widget afterwards. However I don't know how to destroy a widget component.
If I try to simply remove from parent I get the following warning:
UWidget::RemoveFromParent() called on '/Engine/Transient.UnrealEdEngine_0:GameInfoInstance_C_0.DamageWidget_C_12' which has no UMG parent (if it was added directly to a native Slate widget via TakeWidget() then it must be removed explicitly rather than via RemoveFromParent())
I also don't want to use the same widget component (and set the new widget as the existing one) because it overwrites the existing widget component and cancels the animation if two widgets are spawned at nearly the same time(which I don't want).
How can I destroy my created widget component? I also don't want to just hide it because of memory issues.

Using concurrency to have backWorker .swf (animation on displayList) to use it in mainWorker app

I have main application app.swf to which I embed backWorker.swf which contains just animated MovieClip which is added to stage (backWorker's stage). As my main application load and initialize all the content (unfortunately I can not shift this functionality to backWorker) I wanted to have loading animation (fake preloader) in the backWorker. I successfully established communication between these two (through MessageChannel - I try to use send() and receive() methods to gets content from back to main worker), but have no idea how to render (by adding to stage with addChild()) backWorker.swf in its own proccess as I cast the backWorker.swf file as byteArray object in app.swf
Is it even possible ?
You can't show display objects in your Worker instance as it doesn't have a stage. If you wish to show a progress bar, you'll have to show it in the main application. In fact, from your description, you're doing the exact reverse of what should be done - have the main .swf show the progress and the worker doing the heavy processing in the background.

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{
}

AS3 interclass variables

I have a button, that's a class, say, Button. And a main document(class Main) where I can see all the changes in a text field, refreshed every frame (yeah, I don't like trace()). The button has a function of changing a variable that's used in main file. So when I press the button, that I add in the main file to the stage, I need it's function to work. Button class has this.addEventListener(MouseEvent.CLICK,function), further function adds to the var from main class. So if it did add, I would see the changes in the text field. I see changes made by an object I add directly, in the graphic editor, but no changes from the button, whose child I add. Variables are public. Functions are all public. So...
Classes cannot exchange variables freely?
How do I change a variable via a function in a different class?
Maybe I need to export and import var? I thought they all work as a united program that shares all public variables.
Main: I create var i, add Button child to stage and show i every frame =D
Button: When you press me, I add 1 to i =D
SherWood: Main, Y U don't show i, changed by Button? T_T
Code example:
http://piratepad.net/g5tTMFX4Bo
The Button (or any other class) has no built-in knowledge of the environment that is using it's instance.
The DisplayObject ancestors have the ability to check the parent container, and "main" container via parent and stage properties.
The programmers role (you) is to code flexible way to exchange information that any 2 (or more) classes needs to have, e.g. by exposing public methods/properties, dispatching events (that other party can listen) etc.
So, if the Main needs to know that Button (instance of Button) was clicked add listener to that button for click event, and then you will be able to do whatever you want e.g. add one to i
If Button then, for instance needs to present up-to-date value Main via exposed method can do that e.g. myButton.setLabel("Value of i="+i); which may be executed in aforementioned click listener,
regards

ActionScript 3 Best place to bind events

I am writing a small Flash game using air for android and have encountered a slight issue.
The game has 3 screens (excluding the game screen) which are main menu, load game & create new game. On the load game and create new game screens I want to add a button which take the user back to the main menu.
I know how to add event listeners to buttons but I am wondering where do I bind the event listener for back to main menu, binding in the constructor of my main class produces an error at run time and binding after going to the frame is knocking out the other buttons when back at the main screen.
At present the app is across multiple frames (probably a better structure to this instead of loading a single frame with each menu), I am new to actionscript so I am not entirely certain on best practices for this sort of thing.
Thanks.
I recommend you to use only one frame in your Fla, then use a Document Class. In that main Class, you should place all your display objects using ActionScript.
I hope you know how to instantiate Class as library clips.