Actionscript 3 :: Is There Any Point In Globals Or 'evil' Singletons
Feb 3, 2011
I previously used Singletons for global classes, if it's absolutely necessary i.e. logging, error handling. But I am now using unit testing which doesn't like these! I would like to ask a basic question on globals. What's the point in them? What's wrong with creating a new instance of a class when you need it?
View 2 Replies
Similar Posts:
Mar 22, 2011
I'm dealing with the scenario whereby my code might be included in other Flash content either included via import .as commands and then referenced as a Singleton, e.g.
import com.as3.Singleton;
Singleton.birth();
Singleton.getInstance().test();
[code].....
View 2 Replies
Sep 16, 2010
I work mainly in C++, and at work we use this awesome autonomous singleton pattern where you automatically add statically instantiated classes to some global list. If you're familiar with c++, imagine something ala:
class CuteSingleton : public ISomeInterface
{
*** stuff ***[code]...
So basically, CuteSingleton is instantiated at DLL load time and added to a global list of ISomeInterface interfaces. This is really powerful because it lets us rapidly prototype tons of code without polluting our existing codebase by having to include these prototype files, instantiating classes like CuteSingleton in a big initializer list somewhere, etc.I've been trying to figure out how to do something similar in actionscript for a few days now and I'm coming up empty handed. All I want to do is have this code instantiate this class without having to reference it in some other files:
package EntitySystem
{
public class EntityManager extends AutoGameSystem [code].............
View 4 Replies
Dec 14, 2011
I have an AIR application that uses Singletons to manage global state throughout the application. Works great for what it does (manages a network appliance). But now the client wants to spawn multiple application instances from the first instance so they can manage multiple hardware devices at the same time ... kind of like a dashboard but lots bigger.
As you can guess, I coded myself into a corner with the singletons so if I refactor the application to have a bootstrap class that launches the application logic with a button, let's say, that spawns another window that contains the same application logic, then the singletons are shared across both app windows whereas I would have liked two separate instances.
Is there a way to use singletons ( or something else ) to keep global state but create multiple instances in one application where each instance needs it's own state manager?
View 1 Replies
Mar 9, 2012
I'm just starting working with AS but I'm a pretty experienced programmer. AS syntax and Adobe Flash are often driving me crazy but usually after hours of days of struggling I get what I want. Not this time though. In the game I'm making I have a global variable that counts your steps. I made a dynamic text field and as its variable I typed: _global.mile And now the fun part. It's not refreshing. When I leave the frame and get back to it, it's updated, but it's not being updated all the time. To test this, I put this code in onEnterFrame function:
[Code]...
View 5 Replies
Jul 30, 2005
I have Flash site with different .swf's.
[Code]....
In projector.swf I have a movieClip with 2 buttons for language: nl_btn & eng_btn. Clicking makes the _global.taal change to "dutch" or "english". menu.swf gets the global and responds, but all the movies loaded in _level0.container_mc won't get the globals set by projector.swf. Now that menu.swf is in as1 i thought this would be the problem, but changing the _level0.container_mc movies into as1 I still couldn's trace the _globals.
View 2 Replies
Apr 3, 2009
I have a flash site which is going to have a concertina menu and various other features. I need to know if the menu is active or inactive so am using a Global variables class to do this. I have a couple of questions.(i) is this a legitimate technique, to have globals to store and share the state of the menu between all my classes(active or inactive)(ii) What should (if anything) the globals class extend?Also I create my global like this
package
{
public class MyGlobal
{
public var test:String;
[code]....
View 3 Replies
Mar 2, 2011
Suppose I have an application and a global event listener in it. Should the key events, who are fired in the PopUp, be caught by that listener? Or maybe popups are not placed in that hierarchy?Here's simplified test-code for you to understand what I'm talking about:
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script><![CDATA[
private function init():void {
[code].....
View 1 Replies
Dec 9, 2011
Im pushing Point locations into an array to Shift em out later. like this:
tempmoves.push([new Point(roundx,roundy)]);
..
ob.movestoplayer = tempmoves;[code]....
What am i doing wrong?
View 8 Replies
Apr 12, 2007
It's been a long time since I've done any work with actionscript, and alas I've forgotten nearly everything. I've tried to look for a tutorial that would explain basic animation with actionscript, but the one that I found on Kirupa was no longer there.
Basically I'd like to do this:On the stage I have a movieclip and I'd like the movieclip to move along the x-axis to a certain point and then back to the starting point again. The moving speed of the movieclip should also be adjustable.
View 8 Replies
Feb 8, 2009
I'm creating a game in flash for a university project, and learning actionscript and programming as I go. I'm very much still at a beginner level - at the moment al I have is some actionscript for drawing rectangles and moving them about the screen. This is what I'm having trouble with at the moment: I have a class called 'Creature', and I want instances of it to interact with each other. I want them to do something when they come within a certain distance of another instance. And I want them to be able to pick a random other instance to get the location of, in order to do something with that information.
What I think I need is: A function for telling the distance between two (x,y) points.
A way of referencing the nearest other instance of the class. And a way of randomly selecting from all of the instances of the class.
View 4 Replies
Mar 27, 2011
How to convert 3d point to 2d point? I've found next formula in Internet(camera is situated in origin)
[Code]....
But these formulae give me strange result when z are less than zero(z<0) I need build line from A(100,100,100) to B (100,100;-100) As you can see these equations give really strange result when I try to convert B point in 2D dimension
View 1 Replies
Jul 15, 2011
i have the follow issue :
I have a point which is setted at the border on a component, with changed transform point to the center of a component in order to match the component rotation.
the important part is when i try to get the point XY after rotation - they remains the same as before rotation.
how to get XY, after rotation ( changeing point.rotation property to specific degrees of rotaion )
View 2 Replies
Aug 19, 2009
I am using AS2 with Flash 8 Professional So, my problem is that I currently have a man in the middle of the screen, who shoots a line towards the mouse when I click. However, when I use hitTest to see if the line collides with another object, Flash recognizes the line as a large box if it is diagonal, so the hitTest isn't very accurate. The line only satys there for one frame, so I can't have the usual moving-bullet-style. I am either looking for a way to create an imaginary line with AS from the starting point to the mouse and beyond, and tell whether or not this line intersects with an object... or some other way that I haven't thought of to fix my problem. Keep in mind that the line rotates from a center point towards anywhere around it for 360 degrees.
View 1 Replies
Aug 20, 2009
if i have a movieclip or a sprite could i find (via code) where is its registration point compared to its top left point (no rotation included) ?
View 4 Replies
Apr 27, 2004
my preloader bar isn't growing smoothly. it appears to jump from point to point -- and i want to make it smooth. you can see the example here at: [URL] would anyone mind taking a quick look at the file i've attached,
View 6 Replies
Feb 19, 2005
I know some basic trig. but how do i find an angle from an anchor point and a moving point?
adjecent = _root.anchor._x-_root._xmouse;
opposite = _root.anchor._y-_root._ymouse;
hypotenuse = ((adjacent ^ 2)+(opposite ^ 2)) ^ 0.5;
View 2 Replies
May 3, 2006
How can I move a point (or circle) slowly and the point let behind a line.When the point turn back the line will be erase.
View 8 Replies
Mar 28, 2011
Hi I am trying to create an image scroller that just scrolls images from point a to point b on load horizontally in an infinite loop. I just used a code snippet to move it horizontally but don't how to get it to stop and at point b and loop again from a.
ActionScript Code:
game1.addEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally_3);
function fl_AnimateHorizontally_3(event:Event)
{
game1.x += 20;
}
View 0 Replies
Oct 27, 2011
Lets say I have two objects, and I want to use action script to draw a line connecting them, which will update automatically as they are moved/ dragged.Can anyone show me how to do that, and also how to control line's parameters like colour, weight etc?
View 1 Replies
Jan 12, 2012
I am trying to develop a Quadratic Bezier Curve using the graphics.curveTo() method. Initially when i drag mouse to draw the shape, i use start point and end point of mouse to draw the curve line. I assume control point at any position below or up to the line. An draw the curve using this control point. some what like:-
[Code]...
Now i add a tip on this curve segment. I have x and y position of tip. I want to change the curve segment by dragging tip. but now i don't have the exact control point according to tip position. If i use tip coordinate as control point it reduce the height of curve and now tip does not lie on the curve segment. What i have to do is calculate the exact control point on the basis of tip coordinate. But i failed to get this point.
View 1 Replies
Mar 27, 2008
how to use these in order to make an object move from point A to point B in an arc.Think of that classic game where you have to input the angle and power and try to hit your opponent.
View 1 Replies
Nov 9, 2010
I'm trying to figure out how to find a point relative to the center of an object, modified by its rotation. For example, in the attached swf, I've been messing around trying to draw trails to a bitmap, coming out of the thrusters. I didn't have a problem at first, but as the ship rotated, the lines that were being drawn wouldn't remain relative.
http:[url]....
I'm sure this is because I have no idea what I'm doing, and I've just been sort of idioting my way through it. That aside, is there an easy way to find the point I'm looking for? For instance, say I want a point at Y -14 of my ship, but I want that to remain relative to the ship as it rotates.
View 14 Replies
Nov 3, 2003
From the Robert Penner code given in this tutorial: [URL] i was wondering why controlx and controly has to be so complicated. I've tried changing it to just _root._xmouse but it messes up. I don't get this, shouldn't the curve point be the same point as the mouse?
View 13 Replies
Dec 30, 2003
how 2 sript: to draw a line ( 4 example ) frm point A to point B and then code it such that the viewer can see the line being drawn ?
View 9 Replies
Sep 2, 2010
i have this code i found that smoothly moves a box left or right on the screen based on using the left or right arrow keys. i want to use this smooth code but adjust it so on enterframe, the box would move from point a (say 0,120) to point b (0,240) and stop there.no keys used, just working based on entering the frame.how to modify the code below?
Actionscript Code:
import flash.display.*;import flash.events.*;import flash.ui.Keyboard;var velocity:Number = 0;var acceleration:Number = 0.2;var friction:Number = 0.90;var isRightKeyDown:Boolean =
[code].....
View 4 Replies
Jan 9, 2006
Basically what I like to ask is how to move a object from one point to another point based on the point tat you have clicked on a graph. For example, If I click on this coordinate (2,3) on graph, the object (movie clip) will move to that point.
View 3 Replies
Jun 19, 2011
how to get items from an array between 2 points. ie ActionScript Code:array:Array = [mc,mc1,mc2,mc3,mc4,mc5,mc6,mc7,mc8,mc9,mc10] how would i say items 3-7 with out deleteing them or removing them from the array. just to expalin what im doing. i have created a grid and pushed then into a array. i have created a add function which add a movie clip to a certain point in the array specified by the user. but im trying to create a populate cell-cell so user can populate more the 1 at a time. here is the code im useing to add 1 tile to the grid
[Code]...
View 5 Replies
May 8, 2004
if i move the cursor to a point A, it automatically moves by itself to a point B. then if i move the cursor from B to a point C, it bounces away to a point D. i stumbled upon this site while googling around. i'm not a techie, but yeah, i can handle word processors.
View 5 Replies
Feb 8, 2008
When I right-click a symbol the options "set transformation point" and "reset transformation point" come up. They don't seem to do anything for me. I thought it would center them or something. This is not the case. I have the white transformation point in one corner in one keyframe and a different corner in another keyframe I click "reset transformation point" on both frames and they don't move.
View 3 Replies