Find all instances in a currentFrame (AS 3.0) - actionscript-3

I have a movie with several imported videos which are instances of FLVPlayback. I want to make some Pause and Play buttons. Thus I need to know which video should I refer the stop() method to when I'm in a certain Frame. I believe it is something related to finding all existing instances in this.currentFrame and stopping the found instances. Please, Help!!!

you should be able to loop through numChildren using getChildAt() method.

Related

how to I make my flash AS3 game save progress

I have this flash game that I've been working on that works out of the browser, and I'm looking to get it to save it's progress.
I've seen multiple flash games that have accomplished this, and It appears as though they've done this client-side, and I'd like to do the same.
My game consists of 1 mxml file and a number of .as files and I compile it from the command line using flex sdk.
What do I have to do to be able to save save my game's data?
As others have mentioned, SharedObject is the tool you'll use for this.
The basics of this are to initialize a reference to a SharedObject using its static method .getLocal() first:
var mySaveData:SharedObject = SharedObject.getLocal("SomeSaveName");
The String given to this method should not contain spaces.
Once you've done this, you'll be able to use mySaveData.data, which is basically a simple object that you can attach properties to on the fly (it's dynamic):
mySaveData.data.levelsComplete = 2;
Once you've done this, you'll be able to reference that value later on using the same process:
trace( mySaveData.data.levelsComplete );
For simple stuff you can use SharedObject
One way is to use flash's SharedObject to save values in to a 'flash cookie' on the client. Example can be found here: Actionscript 3 saving currentframe location to local hard drive?

Flashbuilder: ActionScript only Project, compiler metadata

If one creates an ActionScript only project in Flash builder, one can set things like stage size and framerate as metadata like this
[SWF(width='400', height='300', backgroundColor='#ffffff', frameRate='30')]
as described here: http://www.adrianparr.com/?p=36
I wanted to ask what other settings i can set using such metadata? is there somewhere a complete list?
See Adobe's documentation:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf680e1-7ffe.html

Actionscript: SharedObject and addEventListener

Could someone explain when does local SharedObject triggers event handlers added via addEventListener?
I have tried and it doesn't trigger, after flushing.
For example i have two object.swf both in separate browser tabs.
I'm adding data inside object.swf on one tab and want event to be triggered in object.swf from another tab.
Is it possible with native functionality and without remote type of SharedObject?
Ofc i could write infinite loop and check local storage for changes, but it's the last solution i would like to implement. :D
I was reading docs and played with example over there, but it doesn't trigger event, even if it is added before flushing.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html
Thanks.
Only remote shared objects dispatch events. If you want to communicate between two swfs, try LocalConnection instead. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/LocalConnection.html

Restart flash on click

I'm trying to restart my flash piece with a restart button. I use gotoAndPlay(0), but nothing happens. I'm sure the click event handler is being called because I used a trace statement to verify.
rs.addEventListener(MouseEvent.CLICK, restart);
function restart(event:MouseEvent):void {
gotoAndPlay(0);
}
The first frame is frame 1, not 0.
Not sure why adobe decided against making frames zero-based, but they did :/
If you have added objects to the stage, like buttons or graphics, but never actually used the stage's timeline, the stage will start and stay at the first frame. So 'gotoAndPlay' wont work in this case. It would be only useful to restart an animation anyway, as it won't reset any code on its own.
You need to decide what parts you actually want to reset and what parts you can keep. You probably don't want to remove assets from memory you loaded at the beginning just to download them again. Some objects may be kept, others should be removed.
As far as I know there is no easy way to reset a flash application, other than maybe reloading the whole page. Here are some general steps to 'reset' an application by hand:
Create a method for your initialization code:
object creation, adding to the display list, adding event listeners.
On a click: remove all objects from the stage, remove all their event listeners.
Call the initialization method again.
Ideally you set the references in your init method to a new variable so the old ones can be garbage collected. Depending on the code structure you may have to manually set some to null. Make sure you don't keep any references to objects you don't need any more.

When building custom panels for Flash CS4 IDE, is there a way to attach callbacks to workspace events?

Is there a way for a custom panel for Flash CS4 to register for IDE events?
I've built a custom panel for the CS4 IDE, and now I'd like to get a callback anytime the current selection on the stage changes. Is this possible?
My backup plan is to have my panel poll the IDE for the selected object several times a second, but this is weak, and won't extend to other kinds of events like deleting objects from the stage or saving the file.
Thanks, Matt
In CS4, yes there are a few events.
There is no selectionChangedEvent unforunately,
buy maybe you can work out something using frameChanged or documentChanged.
DocumentChanged might be more often than you need. Try on frameChanged.
More events are listener in the fl.addEventListener() reference.
Also, here is a handy post on fl events and swfPanel.
Goodluck!