Actionscript 3 :: AddEventListeners And Best Practices?
Jul 16, 2011I'm using this simple code to retrieve a value from a PHP script:
package
{
import flash.display.MovieClip;
[code]....
I'm using this simple code to retrieve a value from a PHP script:
package
{
import flash.display.MovieClip;
[code]....
this a sample code that im currently using...but i need to find a way to do this long script, as short as possible..
btn1.addEventListener(MouseEvent.CLICK, goto1)
btn2.addEventListener(MouseEvent.CLICK, goto2)
btn3.addEventListener(MouseEvent.CLICK, goto3)
[code].....
Don't care about that squares that is inside the functions, I'm just using it as a example.I'd like that both eventlisteners when removed use the same onclick3 function, in the following code they recognize the onclick3 because it is outside of the eventlisteners. So, how can I remove the eventlisteners and both of them use the same onclick3 function?
[code]...
I need both of them to use the same onclick function, and not 2.
I have a polymorphic situation that is thus...
Code:
private var loadXML :ILoader;
if (!Capabilities._internal) //testing locally
[code]....
The following creates movieclips from XML. Everything worksgreat.One problem however. I need each MC to have it's own mouse event listener anddon't know how to achieve this because I don't have specificinstance names to refer with. I want to update textfields etc, with specific data when a
View 3 RepliesIs it possible to addEventListeners to video objects ?
ActionScript Code:
var vid:Video;
...
[code].......
i have to make a drag and drop thingy in actionscript 3.0. Now we had another actionscript project before and then i had some extra classes but most things i put in the main class and it was all working fine. Someone told me that i put too much in my main class and that i should make more classes like a class for every object you interact with. Dont know if hes right but he acted like he was.
Now back to the problem. I made a main class connected directly to my fla in its properties. Then i made another class for the game itself, cause maybe it needs an intro and other things so i want to separate them in their own classes and start them with the main class. now in the class for the game itself i want to be able to click an object with the mouse. I was just testing with a trace. When i click the object it only traces like 1/20 clicks i make, tryed alot of things, when i put the same code in the main class with stage.addEvent blabla it will respond every time but as soon as i try to put in the class for my game it only responds like 1/20 times i click. Wth?
Now i can put all my code in the main class again and make another 1000 line code with a couple of other small classes but this time i want to do it right so what am i doing wrong? Heres some code too
This is the main class dressUp is the game class, it doesnt do much just define the game class and change the mouse pointer.
EDIT: We work in a project group so another reason i want to make alot classes is so we can work on different classes separately. But i promised to have this done this weekend and there not so good in actionscript either.
ActionScript Code:
package
{
import flash.display.*;
[Code].....
I have created a simple game which is started by a start button in a Movieclip that opens at the beginning using the code :
var splashscreen:MovieClip = new Splash();
splashscreen.x = 0;splashscreen.y = 0;
addChild(splashscreen);
The splashscreen movieClip has its own code :
Play_btn.addEventListener(MouseEvent.CLICK,playgame);
function playgame(e:Event):void{parent.removeChild(this); Play_btn.removeEventListener(MouseEvent.CLICK,playgame)
}
When I run the game the splashscreen does load and then disappears when the Play button is pressed but none of the eventlisteners seem to work. The background moves, the enemy ships fire but I can't move the ship or fire using the keyboard. The game works perfectly well when I don't use the splashscreen at the start.
This is probably something very simple that I just can't seem to get to work. Basically I'm trying to use a variable to be called inside of an array instead of the actual array so a simple example would be
Code:
var people:Array = [john,tom,ann];
var selected = john;
trace(people[selected]);
I get an error everytime I try to use a variable in place of and actual element
[Code]...
Using CS5 AS2.I'm creating a website in flash (all the files will be in one directory/folder on SharePoint) and want to make sure that what seems to be working fine is best practice.I have an index.swf with many buttons which will take the user to landing pages/content/other swfs. On these different buttons I have the script [code]The movie transitions nicely to name.swf and on this page I have a button that returns the user to the index.swf on (release) {loadMovieNum("index.swf", 0);}Things move back to index.swf nicely and user can chose to go to another landing page.It looks like I'm on the right track, bc nothing is going awry? but want to check. Am I following best practices for moving from one swf to another within a website?
View 3 RepliesI've been working on a game the past few days where there is to be a LARGE amount of stored data. By a large amount, I'm talking something like 200+ entries of around 12 fields.The game is being designed with the intent of playing it online (per say), so I can't rely on storing specially made files on one's computer (Not that I think I could and do it in a way where players cannot modify it). I also do not want to rely on a stored XML file on the internet or on a database, because if the website that has this data goes down or if the person loses internet access, then the game becomes unplayable.So, I need to store this data in the game itself, but I am unfamiliar with the best way to go about doing this. I've normally worked with outside sources for data storage, as they were designed in closed environments (aka intranet) or the website that the SWF would be on would also be where the database used is stored. Neither apply to this game, as the game will likely be put up on Flash portals like Newgrounds.
View 17 RepliesWe have recently deployed Flash Media Streaming server 3.5.2 and Flash Media Encoder on a Windows 2003 machine. Do you guys know of any security best practices to follow for the FMS server deployment on a Windows machine, could you please point me to that resource.
View 2 RepliesWhat are, nowadays, the best practices for uploading a large file (which may cause a timeout) with ASP.NET Web Forms and/or MVC? Increase Server.ScriptTimeout (only for the specific POST request); Use some flash client-side uploader like swfupload ([URL]) or plupload ([URL]), but Flash uploads have some issues with proxies; Use some gmail-like javascript (like [URL]
View 2 RepliesWhen I create a website,I always end up with 2 preloaders... one to load the main swf (library items, etc...), and then a second preload takes place to load all the external images from XML.Is there a better way?I don't like the fact that there are two progress bars that run or a long pause in the beginning prior to the 2nd preloader. Please let me know if I'm missing something or if you follow any design patterns or best practices.I often run across sites that have one load and then images throughout the site load rather quickly.
View 0 RepliesI have a question about how best to remove display objects.removeChild(object);Given that there are no other reference to this object, does using removeChild alone make the object eligible for garbage collection, or does it also need to be given a null value as well?[code]In both these cases, I get the classic 1009 error. That leads me to believe that if you use removeChild, you don't also need to give the object a null value.?url...
View 2 RepliesI've been building Flash web sites for a long time now, as a freelance developer. I usually work alone, and so I'm the only one that touches the production work I do.Since I'm in this working position, I don't get a lot of exposure to other styles of flash production. I was wondering if any of you have examples of the best ways to produce high quality flash websites. I'm not talking about huge team projects, but small 40-50 work hour sites.[code]
View 2 RepliesWhat are the best practices for optimizing a transparant png image? What things can be done to make such a png file as small as possible without loosing to much of its quality? Best tools? Best Photoshop plugins? Other tips?
View 2 RepliesLet me start off by stating that I am a novice developer, so please excuse the elementary nature of my question(s). I am currently working on a Flex Application, and am getting more and more confused about when to use server side scripting, and when to develop web services. For most of the functionality I am working on, I am taking various files from the user (client), uploading to the server for processing/conversion, then sending back to client in new format.
I am accomplishing most of this using asp.net generic handlers (ashx) files, but not very confident this is best practice. But at the same time, does making web services make any more sense? What would be considered best practice for this?
Are there any standard practices for Video encoding, streaming, etc?
View 1 RepliesI have a website that has a Flash banner. For devices that do not support Flash (like iPads) I want to display an image instead. What is the best practice to deal with this situation? Should this be handled from the front-end with JavaScript?Should this rather be handled from the back-end? (I am using Java on the back-end)
View 1 RepliesI have an application with about 20 models and controllers and am not using any particular framework. What is the best practice for using multiple remote objects in Flex performance-wise?
1) Method 1 - One per Component - Each component instantiates a RemoteObject for itself
2) Method 2 - Multiple in Application Root - Each controller is handled by a RemoteObject in the root
3) Method 3 - One in Application Root - Combine all controllers into one class and handle them with one RemoteObject
I'm guessing 3 will have the best performance but will be too messy to maintain and 1 would be the cleanest but would take a performance hit.
I'm building my first Flash application. It's a stand alone barcode scanner - the scanner is built-in to the monitor. Basically it has a welcome screen with a video, and at any time you can either scan a product to get product info, or touch the screen for more options (more info, more videos, etc.), respectively.I'm looking for articles, tutorials, etc. that can give me best practices and tips for efficiently designing and organizing it. For example, what's the best way to switch between screens, keep track of which screen is showing, etc.
I've looked all over the web and can't find an article or tutorial on this, and while my app is working, the code is looking pretty spaghetti-ish and I really would like to learn the best way to plan and organize a project like this.
I thought i'd start this thread to uncover peoples habits and practices when it comes to the simple operation of adding and removing elements on stage. I ask because there are so many alternatives, and I keep wondering what might be the best/most eficcient way of doing it. Let me explain by giving an example:
Your user has chosen to click that flashing button that says "Sign up for our mailing list" and you need to prompt the user for a valid e-mail address by presenting him/her with an alert box on top of everything else. Do you.[code]....
If I've got a getter method, say a(), that returns the private variable _a. Obviously from outside the class I call instanceOfClass.a. But from inside the class, should I use the getter or directly _a? Suppose I'm writing a method that uses _a: should I use _a or a? var b = a; or var b = _a? Maybe for performance reasons it's better to directly access _a? Or since there's a getter a(), it's a good practice using always and only the getter?
View 8 RepliesAnyone have any tips for good practice with using event listeners? I've gotten into the habit for checking for event listeners (hasEventListener()) prior to removing them, but no errors are thrown if you try to remove an event listener that does not exist, so should I even bother?
Also, I've often gotten into the habit of checking for a listener prior to adding it sometimes, just to make sure I'm not adding it twice (mostly due to slightly sloppy code when they're added/removed on an as-needed basis). But doing a quick test, it seems this is also not needed. It seems adding an event listener of the same type with the same handler twice overwrites the first:
Code:
stage.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
stage.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
// traces 'true'
trace(stage.hasEventListener(MouseEvent.MOUSE_DOWN));
[Code]...
Since there's so much potential pollution within namespaces, particularly with the parser automatically declaring any MXML component with an id to be publicly-accessible using that ID I'm finding it dangerous to use just camelCase for MXML element ids. eg:
[Code]...
In Flash development, a lot of us did this for (automatically) declared stage instances like "mcMyTabBar" or "navMC" or "playPauseBTN". I'm looking for input from the Flex community about this. Am I just overthinking things? All of the related Style Guides and best practices documents I've read on the topic just say "use camelCase for ids, and make sure the id property is the first property". What's your take?
I have a bit of Flash experience, did a full featured movie player, other stuff in AS3 and got plenty of programming skills in other languages, BUT now I need to create a multi paged website. Quite easy, a few pages, some animations here and there, nothing fancy, got all the graphics.
But time is short on this one, so I need some advice about good practices (pack everything into one main MC or make separate swfs and load them in, etc.), where to begin, or what kind of book should I grab to make the job pretty.
I'm creating a drop down menu and when I addEventListeners to check the clicks on the invisible buttons on frame 19 of the "menu" movieclip, it gives me an error. T really hate doing rollover with actionscripts. The download link for the fla can be found in below. Sorry for posting an external download link as the file is 7mb+! [URL]
View 2 Repliesanyone know of a good resource for banner development tips and tricks - mainly in regards to image optimization, external imports and filesize reduction. Its been a while since i have looked into smart ways to pack more clarity and quality into flash banners and wanted to reach out.
View 0 Replies