Re: [Flashcoders] Question about AS3 components
What class are you subclassing to make your component? UIComponent defines a protected measure() function which some other internals use to figure out how big a component is. Maybe you need to implement an override of that? The docs show InteractiveObject having a focusRect property, but they don't give much detail about it. If you're using Flex classes, remember that FlexBuilder comes with the source code for the Flex classes. I have had to resort to reading Flex class source many times to understand things that the docs don't describe well. :-/ Dave On Tue, Mar 17, 2009 at 10:31 AM, Eric E. Dolecki edole...@gmail.comwrote: I have a component I am building that has a default size set with an avatar clip. When it's placed on stage by hand, it uses that dimension and it removes that clip. Great. I have overriden height and width mutators and accessors. When I resize the component on stage, it works correctly, but I have the blue outline selection box at the default size still, not properly bounding the resized contents of the component. Is there a trick I should use here? -- http://ericd.net Interactive design and development ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Advice on creating random grid of pairs for a game
My first thought for your algorithm is to essentially follow the solution path that your user might end up taking. Your user will be clearing areas out, opening them up. Your algorithm could start with an empty grid and fill in around a starting seed, growing the tile array outward. 1) empty grid 2) generate random sequence of pairs with the blank embedded in it, such as 4,4,27,27,1,1,36,blank,36, etc 3) choose random location for first tile, and place it there, and take it off the pair queue. 4) choose an unfilled location which is 4-connected to any filled location, and put the next tile from the queue in it. 5) repeat 4) until the queue is empty. In this system, putting the blank in a location counts as filling that location, so the value for blank needs to be different than the initial values in the grid. So for example, if -1 means uninitialized and 0 means blank: -1,-1,-1 -1,-1,-1 -1,-1,-1 then -1,-1,-1 -1,-1,04 -1,-1,-1 then -1,-1,04 -1,-1,04 -1,-1,-1 then -1,-1,04 -1,27,04 -1,-1,-1 then -1,-1,04 -1,27,04 -1,27,-1 then -1,-1,04 01,27,04 -1,27,-1 then -1,-1,04 01,27,04 -1,27,01 then 36,-1,04 01,27,04 -1,27,01 then 36,00,04 01,27,04 -1,27,01 then 36,00,04 01,27,04 36,27,01 This guarantees that a solution exists, because the algorithm essentially traces out the solution as it generates the level. This presumes that players are not allowed to move tiles around yet leave them on the board while solving the puzzle - it assumes that tiles just disappear from the grid when the user selects a pair which has a clear path between it, and that's the only interaction allowed. If they can slide them around, my algorithm will still produce solve-able puzzles, but they won't be as difficult as they could be, I think. :) Interesting problem! Dave On Wed, Mar 11, 2009 at 6:09 AM, Glen Pike g...@engineeredarts.co.ukwrote: Jobe Makar's book about Flash Games Demystified has a wordsearch that shuffles words in a grid - it will keep shuffling upto a point, then decide that it is getting nowhere and try again. There may be some examples of this sort of thing online - I have the book at home if not :) Paul Steven wrote: I am trying to write the code to populate a 9 by 9 grid of tiles with 40 pairs of matching tiles. I have 4 different types of tiles and I want to create a grid that has 40 matching pairs and 1 blank tile. I do not want the pairs all to be next to each other but there needs to be at least one solution that enables a player to match each and every pair. To match a pair there needs to be a clear path between each member of the pair. 1,2,1 2,0,3 4,4,3 In this simple example, a user could clear all tiles by matching in the following order: 4 - 4 3 - 3 2 - 2 1 - 1 Note that until they have matched the pair of 2's they cannot match the 1's as there would be no clear path between them. All my attempts so far to create this grid is resulting in script errors due to my code being unable to find a solution. My code basically gets about 60% of the board created then finds it cannot any more clear paths to create the remainder of the grid. I would really appreciate any help cracking this function. Thanks Paul ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] where did the mouseX go?
mouseX and mouseY are member variables of the Sprite class. You don't need to import member variables, only classes. Once you import the Sprite class, all the members come with it. replace your mouseX and mouseY imports with: import flash.display.Sprite; and you'll be golden. Dave On Wed, Mar 11, 2009 at 10:18 AM, Gustavo Duenas gdue...@leftandrightsolutions.com wrote: Hi Coders I have this code, is simple I want to move something using as3, but when I do the movie test with it, it gives me this error 1172: Definition flash.display.Sprite:mouseX could not be found. same for the mouseY, I don't understand since the code appears to be in the import flash.display.Sprite.mouseX; doers anyone has encountered this error, am I doing something wrong, and please if someone knows what is would you please point which is the error there. I'd appreciate any help, here is the code import fl.transitions.*; import fl.transitions.easing.*; import flash.ui.Mouse; import flash.display.MovieClip; import flash.net.*; import flash.events.*; import flash.display.Sprite.mouseX; import flash.display.Sprite.mouseY; var duration:Number = 3; var cosilla:Sprite = new Sprite(); var cosillaLoader:Loader = new Loader(); cosillaLoader.load(new URLRequest(http://leftandrightsolutions.com/ back1.jpg)); cosilla.addChild(cosillaLoader); addChild(cosilla); addEventListener(Event.ENTER_FRAME, mousecords); var xTween:Tween = new Tween(cosilla, x, Regular.easeOut, cosilla.x, cosilla.x, duration, true); var yTween:Tween = new Tween(cosilla, y, Regular.easeOut, cosilla.y, cosilla.y, duration, true); function mousecords(event:Event):void { xTween.continueTo(event.mouseX, duration); yTween.continueTo(event.mouseY, duration); } Gustavo ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Advice on creating random grid of pairs for a game
Jonathan, When you match a pair, you pull them off the grid. Therefore after removing the pair of 2s, there are only empty squares in the path between the 1s. Dave On Wed, Mar 11, 2009 at 10:43 AM, jonathan howe jonathangh...@gmail.comwrote: Hi, Paul, Can you explain what you mean by a clear path. For example, when I look at this example below: 1,2,1 2,0,3 4,4,3 In this simple example, a user could clear all tiles by matching in the following order: 4 - 4 3 - 3 2 - 2 1 - 1 I don't see the clear path between 1 - 1. Seems like it jumps from one square to another. So is a clear path just a straight or diagonal line between the next number in the sequence that is unobstructed by a non-used pair, or what? -jonathan On Wed, Mar 11, 2009 at 12:59 PM, Paul Steven paul_ste...@btinternet.com wrote: Thanks Anthony Perhaps I am overcomplicating things but I am under the impression I need to ensure there is a clear path between each pair as I add them. My current algorithm is as follows: Step 1. Choose a random tile position (Random Row, Random Column) Step 2. Create an array of all possible tiles that this random tile can be paired with. To create this array, I use a path finding function to check there is a clear path between the 2 tiles Step 3. Choose one of the possible tiles from the array (currently I am just choosing a random one) and update grid data to reflect the 2 paired tiles are not on the grid. Repeat from Step 1 again This works fine until around 26 pairs have been placed then it gets stuck as it cannot find any more tiles that have a clear path. I have even added code to ensure that no isolated empty tiles are created as a result of creating a pairing. I have tried putting several timed break points in my code to restart the entire process if it fails to complete the entire grid. However it just doesn't seem to ever be able to generate an entire grid. Perhaps this process is really time consuming and I need to leave it for hours to generate a grid but I wouldn't have thought so. Any advice much appreciated! Thanks Paul -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Anthony Pace Sent: 11 March 2009 16:31 To: Flash Coders List Subject: Re: [Flashcoders] Advice on creating random grid of pairs for a game Sounds like one of my old high-school projects, I see several ways of doing what you want that make sense: * -random population always of an array 81 units long (80 if you want the last to always be blank) o --you could create a function that loops 41(or 40 if last always blank)times tracking the positions in a temp array and then returning the completed array (if 41st loop choosing unfilled position with a 0 for blank card/wild card) o --there are other ways of doing this; yet, they use more loops and if statements. * -random population of an array 81 units long and then shuffling the deck sort of o --shuffling by swapping only positions that have not been swapped (you could even isolate left and right sides to simulate a card deck getting shuffled by hand) o --shuffling by swapping from 1 to 81 to ensure all positions get swapped o --there are most definitely more ways of doing this * -static population and then shuffling the deck same as above. As well, although I think you may not need to be told this, when you want to display the positions, you need to know and track which row level of the grid you are on and what column position you are in, in order to properly find the x and y values; thus, in your case testing if the modulus of 9 equals 0 will be handy. I hope the concepts help, Anthony Paul Steven wrote: I am trying to write the code to populate a 9 by 9 grid of tiles with 40 pairs of matching tiles. I have 4 different types of tiles and I want to create a grid that has 40 matching pairs and 1 blank tile. I do not want the pairs all to be next to each other but there needs to be at least one solution that enables a player to match each and every pair. To match a pair there needs to be a clear path between each member of the pair. 1,2,1 2,0,3 4,4,3 In this simple example, a user could clear all tiles by matching in the following order: 4 - 4 3 - 3 2 - 2 1 - 1 Note that until they have matched the pair of 2's they cannot match the 1's as there would be no clear path between them. All my attempts so far to create this grid is resulting in script errors due to my code being unable to find a solution. My code basically gets about 60% of the board created
Re: [Flashcoders] Advice on creating random grid of pairs for a game
In the following grid, all bs are 4-connected to the one a: -, b, - b, a, b -, b, - So for the sample grid -1,-1,-1 -1,-1,04 -1,-1,04 the cells which are 4-connected to the initialized cells are here marked with xx: -1,-1,xx -1,xx,04 -1,xx,04 In other words, the cells to randomly choose the new tile placement from are the ones at the boundary of the already-initialized region. In the initial description of the problem it sounded like valid paths did not include diagonals, which is why I say 4-connected. If diagonals are OK, use 8-connected. Dave On Wed, Mar 11, 2009 at 1:49 PM, Anthony Pace anthony.p...@utoronto.cawrote: I just wanted to mention that I don't think it should be entirely random. Perhaps you may want to add restrictions as I mentioned before, yet, make sure it has a maximum that steps higher and higher based on availability, and alternate between diagonal and side to side. So if there is no way 2 can be side by side or diagonal anymore, than max distance plus 1, check for a max distance of 1 square/slot between from available slots in the array, and so on. This would allow it to build out and use all available squares. Paul Steven wrote: Thanks David for your suggested solution - it looks very promising. I am not sure what 4-connected means? But I think I understand the general idea I am just wondering if your solution would guarantee that there will always be a matching tile within a clear path? For example if the random sequence is 4,4,27,27,1,1,36,36, BLANK -1,-1,-1 -1,-1,-1 -1,-1,-1 then -1,-1,-1 -1,-1,04 -1,-1,-1 then -1,-1,-1 -1,-1,04 -1,-1,04 then -1,-1,27 -1,-1,04 -1,-1,04 then -1,-1,27 -1,-1,04 -1,27,04 then -1,-1,27 -1,01,04 -1,27,04 then -1,-1,27 -1,01,04 01,27,04 then -1,36,27 -1,01,04 01,27,04 then -1,36,27 36,01,04 01,27,04 then 00,36,27 36,01,04 01,27,04 -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of David Hershberger Sent: 11 March 2009 17:40 To: Flash Coders List Subject: Re: [Flashcoders] Advice on creating random grid of pairs for a game My first thought for your algorithm is to essentially follow the solution path that your user might end up taking. Your user will be clearing areas out, opening them up. Your algorithm could start with an empty grid and fill in around a starting seed, growing the tile array outward. 1) empty grid 2) generate random sequence of pairs with the blank embedded in it, such as 4,4,27,27,1,1,36,blank,36, etc 3) choose random location for first tile, and place it there, and take it off the pair queue. 4) choose an unfilled location which is 4-connected to any filled location, and put the next tile from the queue in it. 5) repeat 4) until the queue is empty. In this system, putting the blank in a location counts as filling that location, so the value for blank needs to be different than the initial values in the grid. So for example, if -1 means uninitialized and 0 means blank: -1,-1,-1 -1,-1,-1 -1,-1,-1 then -1,-1,-1 -1,-1,04 -1,-1,-1 then -1,-1,04 -1,-1,04 -1,-1,-1 then -1,-1,04 -1,27,04 -1,-1,-1 then -1,-1,04 -1,27,04 -1,27,-1 then -1,-1,04 01,27,04 -1,27,-1 then -1,-1,04 01,27,04 -1,27,01 then 36,-1,04 01,27,04 -1,27,01 then 36,00,04 01,27,04 -1,27,01 then 36,00,04 01,27,04 36,27,01 This guarantees that a solution exists, because the algorithm essentially traces out the solution as it generates the level. This presumes that players are not allowed to move tiles around yet leave them on the board while solving the puzzle - it assumes that tiles just disappear from the grid when the user selects a pair which has a clear path between it, and that's the only interaction allowed. If they can slide them around, my algorithm will still produce solve-able puzzles, but they won't be as difficult as they could be, I think. :) Interesting problem! /mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] AS3 - XML Filter by Date
You can filter XML with arbitrary boolean functions, so the answer is definitely yes. See http://livedocs.adobe.com/flex/3/html/13_Working_with_XML_08.html#131880 One of the examples there shows XML stored in var x with a list of employee id=23/ type elements, and you can use this syntax to get an XMLList of employees with id attributes over 300: x.employee.(@id 300) Similarly, if you had a birthdate field stored as milliseconds since 1970 you could filter on that like so: x.employee.(new Date(@birthdate).getFullYear() == 2000) to return a list of employees who were born in the year 2000. (Presumably a short list. :-) Dave On Mon, Mar 9, 2009 at 1:07 PM, Eric E. Dolecki edole...@gmail.com wrote: I suppose if the XML has that kind of data in it you could. On Mon, Mar 9, 2009 at 12:02 PM, Doug Coning dcon...@webize.com wrote: Greetings everyone, In AS3, can you filter xml by a date value or range? Thanks, Doug Coning ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- http://ericd.net Interactive design and development ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] RegExp headache
oops, forgot about the comparison operator being optional. New version: /(((|)=?)|==)?(-?\d+)/ hot darn. Dave On Thu, Mar 5, 2009 at 10:44 AM, David Hershberger he...@zipzapplay.comwrote: How's this? /(((|)=?)|==)(-?\d+)/ Then the comparison operator is in result[1] and the number is in result[4]. You said integer, so I threw in the optional negative sign. :) Dave On Thu, Mar 5, 2009 at 10:02 AM, Glen Pike g...@engineeredarts.co.ukwrote: Hi, How about: /([=]+)([0-9]+)/ Check out RegExr by Grant Skinner - it's lovely. The problem with = and = is that there is look behind in the regex controlled by these chars so the order of = seems to be important??? Glen Jiri wrote: I would like some help on a regExp I have a string and want to split it into the first character being a ||=|=|== the second part being an int. so 100 would return result[1] = '' result[2] = 100 so 100 would return result[1] = 'undefined' result[2] = 100 Here is what I have so far, but it is killing me. var pattern:RegExp = /^(\d)?(^\d+)|(?)/ var result:Object = pattern.exec(tConditionalString); I tried another approach but i am still figuring out how to do it. It goes something like this var pattern:RegExp = /^():((?(2)then|else)) Jiri ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] FDT SVN + Code Assist
In Flex Builder, you can go into the Flex Navigator window (the tree-layout project-contents window), select a directory (like .svn), right-click it, choose properties from the resulting menu, then check the box which says derived. Once you do that, I believe it will recognize that files in the directory and below are not source. I don't know for sure that this will solve your particular problem, but it works for me to keep unwanted stuff out of the Open Resource dialog (bound to C-x C-f with Emacs keybindings, I don't know how to get to it otherwise. :-) I expect it will keep that stuff out of autocomplete and other code hinting. Downside is that there's no way to give Flex Builder a pattern to apply across your whole project tree, you have to manually go through the tree and click it for each directory you want to mark. Dave On Sat, Feb 14, 2009 at 9:33 AM, Karim Beyrouti ka...@kurst.co.uk wrote: Thanks for the reply - i have set the filter to ignore .svn files, however that does not seem to filter the folders from the code hinting... - karim On 14 Feb 2009, at 17:24, ekameleon wrote: Hello :) in eclipse in the FlashExplorer panel in the top right menu of the panel you must choose the item filters and select the .svn files. PS : you use Subclipse ? for me the best solution in eclipse to work with SVN EKA + :) 2009/2/14 Karim Beyrouti ka...@kurst.co.uk Hello All, I am using eclipse SVN with FDT - and for the most part it really works a treat. However, I am getting all the SVN paths appearing in my code hinting. Do you know a way to get code assist to ignore svn paths? Regards Karim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Best way to access my main class?
My preference is usually option 3, using an event. It means you can use your ball in other situations, where that call back to the root may or may not be necessary. Regarding cleaning up references in event listeners, you can use a weak reference when you call addEventListener(). Also, I often find that existing flash or flex events match the nature of what I want to express, so I re-use theirs sometimes which saves writing a new event class. Option 4 would be to make MyGame implement some interface (Game? IGame?) which specifies that function. Then the BouncingBall constructor is passed a reference to the interface instead of the whole MyGame class. Same as option 2, really, but this way it's plausible that you would implement the interface with some other game-like class and use BouncingBall in that. Option 5 would be to pass a Function reference into the constructor of BouncingBall. This is very generic, like the event solution, but has a few downsides: 1) function specifications are not maintained by the compiler when you pass Function references, so if you write a bug into the call of the function, you'll get a run-time error instead of a compile-time error. 2) Exactly one object can listen for this function call, unlike an event, which can be listened for by any number of clients. I often use Option 5 for success and failure callbacks when something won't complete right away. Dave On Thu, Feb 5, 2009 at 9:44 AM, Todd Kerpelman t...@kerp.net wrote: Hey, FlashCoders. I'm wondering if you can help me out with a general style question that I keep running into. Let's say I've got a setup like this... class MyGame extends MovieClip - It creates a camera sprite that I can add children into - It then creates a Bouncing Ball object with the camera sprite as the parent to use. class BouncingBall { public function BouncingBall(parentToUse:DisplayObjectContainer) { // Create member variable _mySprite:Sprite and add it to my parentToUse //... } } For reasons I won't get into unless you're really interested, BouncingBall does NOT extend Sprite, it simply contains a sprite. So MyGame has a camera as a child. That camera has my bouncingBall._mySprite as a child. The question is this: I want the BouncingBall sprite to occasionally call a function in MyGame. What's the best way to do this? *Option 1:* Within BouncingBall, just call... MyGame(_mySprite.root).foo(_myVar); This works, but it strikes me as a little unnatural, since I have to dig into my member variable and get its root. Also, I'm not sure this works if my game were to be imported by some larger, wrapper class. *Option 2: *My constructor for BouncingBall should contain two variables public function BouncingBall (var parentToUse:DisplayObjectContainer, var gameApplication:MyGame) I store gameApplication as a member variable, and use it later... _myGame.foo(_myVar); This is my current solution, but the idea of passing a parent and the game application to the constructor strikes me as slightly redundant, and, like Option 1, it tightly couples my BouncingBall object to my main application. *Option 3:* I create a custom event, dispatch that event, and create a listener in MyGame rather than call a function directly. I'm guessing this is the best way to go theoretically, and will allow me to reuse my BouncingBall object in other applications, but it's a lot of extra code, and I constantly worry about not property cleaning up event listeners. I'm sure all of you have encountered this situation before. So what do you generally do? Is there a fourth, totally obvious option that I'm overlooking? Thanks! --Todd ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] top down plane games
I may be misunderstanding the trouble you are having, but are you looking for sine and cosine? var velocity: Number = 3; // Absolute velocity, regardless of direction speedX = velocity * Math.cos( cursorAngle ); // X component of velocity speedY = velocity * Math.sin( cursorAngle ); // Y component of velocity Or, since you are starting with a dx,dy and computing an angle from that, you can just normalize the vector to whatever length (speed) you want.: var velocityVector: Point = new Point( dx, dy ); velocityVector.normalize( velocity ); // Set length of vector but preserve direction speedX = velocityVector.x; speedY = velocityVector.y; Dave On 1/25/09, Corban Baxter corb...@gmail.com wrote: thanks todd. thats what I have been doing for the most part. I'm working on figuring out how to move the Camera sprite around on an angle. i've got script that makes the airplane point towards the mouse at all times. but thats the easy part. now i need the Camera sprite to move at a consistent rate at the same angle the plane is pointing. Just can't see to figure out what it take to do that. var minXMove:Number = 0; var minYMove:Number = 0; var maxXMove:Number = (levelMap.width - stage.stageWidth) * -1; var maxYMove:Number = (levelMap.height - stage.stageHeight) * -1; stage.addEventListener(Event.ENTER_FRAME, pointAtCursor); function movemap():void { //move on x-axis levelMap.x += speedX; if (levelMap.x = minXMove) { levelMap.x = minXMove; } if (levelMap.x = maxXMove) { levelMap.x = maxXMove; } //move on y-axis levelMap.y += speedY; if (levelMap.y = minYMove) { levelMap.y = minYMove; } if (levelMap.y = maxYMove) { levelMap.y = maxYMove; } } function pointAtCursor(e:Event) { // get relative mouse location var dx:Number = mouseX - plane.x; var dy:Number = mouseY - plane.y; speedX = (dx * -1); speedY = (dy * -1); // determine angle, convert to degrees var cursorAngle:Number = Math.atan2(dy,dx); var cursorDegrees:Number = 360*(cursorAngle/(2*Math.PI)); // point at cursor plane.rotation = cursorDegrees; plane.x -= (plane.x-mouseX) / 6; plane.y -= (plane.y-mouseY) / 6; movemap(); } the hard part is getting the speedX and speedY to be numbers that don't cause the map to fly to fast. Just not sure where to go from here. On Sun, Jan 25, 2009 at 2:42 PM, Todd Kerpelman t...@kerp.net wrote: Well, I'm no plane game expert, but here's probably how I'd approach it... Within your PlaneGame movie, create a child sprite called Camera. Make all your interface stuff children of the PlaneGame movie. But make the background, your plane, the enemies, etc, all children of this Camera child sprite. Then, when it comes to creating the background scrolling below you look, don't have your background move at all. Only have the things that would actually move in real life (planes and tanks and whatever) move. Instead, make your Camera sprite scale and/or move itself to track your plane (or, even better, a point a couple hundred pixels in front of your plane.) That will make it look like the background is moving, but it's really staying in place. And it will simplify your planes and tanks and bullets, because you can basically just look at each sprite's position and velocity, without having to try and somehow compensate for a magical moving background. For development purposes, by the way, I would start your game by not having the camera move at all, and just making sure everything works right in a tiny little world the size of your screen. Once that's working, then you can enlarge the bounds of your world and start moving your camera around. Good luck! --T On Sun, Jan 25, 2009 at 11:16 AM, Corban Baxter corb...@gmail.com wrote: hey guys! I'm trying to build a simplified version of http://www.miniclip.com/games/skies-of-war/en/. Mostly looking to replicated the movement. But I have no ideas on where to start. I'm having alot of trouble setting the angles correctly to give the background a constant speed but allowing it to change angles. I understand its going to be based on the planes current angle. But that's where I get confused on getting the speeds to not over lap and making it seem like it moving faster. Ok I'm rambling now. but I was hoping someone might be able to help me understand this better and give me some examples I could use to get moving. Any help would be great! thanks! -- Corban Baxter http://www.projectx4.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] get PROP from obj.PROP
private function assignContent( parentObject: *, memberName: String ): void is what your function needs to take, and you would call it like: assignContent( msg, ONE ); With assignContent( msg.ONE ) as you have it, the reference to the object stored in msg.ONE is read from msg before and only that object reference is passed to assignContent(). There is no obvious way to recover that connection just from the argument inside the function. References are one-way connections. Dave On 1/9/09, Mendelsohn, Michael michael.mendels...@fmglobal.com wrote: Hi list... I'm passing a var to this signature: private function assignContent(Content:*):void // example assignContent(msg.ONE); How can I get the ONE part of it, so I can correlate with another object like info.ONE, or if it is passed msg.TWO, I can cross reference info.TWO? There must be an efficient way... Thanks, - Michael M. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] ActionScript syntax enhancements?
Dunno if you're going to implement [Bindable], which is I guess part of Flex, but if you do... https://bugs.adobe.com/jira/browse/SDK-14475 and https://bugs.adobe.com/jira/browse/SDK-9804 describe the fact that we can't use data-binding to watch the changes of read-only properties. This ability would allow us to more nicely encapsulate our code while still getting the ease-of-use of data binding. In response to Manish... if you make your public getter and setter contain only pass-throughs to your private variable, why not just make the variable public? Dave On 1/6/09, Manish Jethani manish.jeth...@gmail.com wrote: On Wed, Jan 7, 2009 at 3:59 AM, Matthias Kramm kr...@quiss.org wrote: I'm currently in the process of writing a compiler for ActionScript 3.0. (In case you're interested, the development snapshot at http://www.swftools.org/download.html already contains a pre-alpha command-line tool, called as3compile(.exe)) Now, I'm thinking about adding an extended mode to this compiler, which will support some additional convenience features which are not currently part of the ECMA spec. The first enhancement I can think of is a language extension called 'properties'. private var _myProperty:int = 0; public function get myProperty():int { return _myProperty; } public function myProperty(value:int):void { _myProperty = value; } This pattern is so common, it could be a language feature. public property myProperty:int = 0; There, much better. You can override the property in a subclass, of course. override public property myProperty:int = 1; Or: override public property myProperty:int { var _myProperty:int = -1; function get ():int { return _myProperty == -1 ? Math.floor(Math.random() * 0x100) : _myProperty; } function set (value:int):void { _myProperty = value; } } Then you can make them read-only, write-only, or read-write. Okay, maybe that's overkill. But I'm tired of having to write 7 lines of code just to add one property to a class. Another one is events. I wish events were part of the interface of an object, and I wish all objects were event dispatchers (i.e. Object and EventDispatcher were one). This is much too advanced to call it a small extension to the language though. There's probably a lot of small things you could pick up from other languages like C, Java, etc. Manish ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Custom eventListener
An event is just a message object. Just because one gets created successfully does not mean it is being delivered. dispatchEvent() is a method of the EventDispatcher class, which is a superclass of many classes, including DisplayObject. You need to listen for the event (with addEventListener()) on the same EventDispatcher where the event was dispatched. (Except in the case of events that bubble, but that's another topic.) For example: public class MyWindowHolder extends Sprite { public function init(): void { var a: MyWindow = new MyWindow(); a.addEventListener( MyEvent.EXCLAMATION, onExclamation ); } private function onExclamation( event: MyEvent ): void { trace(ouch!); } } public class MyWindow extends Sprite { private function injury(): void { this.dispatchEvent( new MyEvent( MyEvent.EXCLAMATION )); } } Hope this helps, Dave On 12/18/08, Lehr, Ross (N-SGIS) ross.l...@lmco.com wrote: Hey All... I'm having trouble with a custom event listener. I'm working on experiment browser project trying to learn as3, OOP, and AIR. I broadcasting the URL after a web page is loaded and I need a text box to listen for it. I've added a trace to me urlLoadedEvent class and I know the URL is getting there (so, I think it's getting broadcasted ok), but it's not getting to the text box. I think I have my listener in the wrong place, but not sure where to put it. I don't have my exact code here, but below are some code snippets. Thanks for any and all help. Ross -- DISPACTING EVEN In a loadComplete function urlLocation = text field for the URL string dispatchEvent(new urlLoadEvent(urlLocation.text)); -- urlLoadEvent Class (when I trace urlLocation I am getting the URL string) package { import flash.events.*; public class urlLoadEvent extends Event { public static const URL_CHANGED = urlChanged; public var urlLocation:String; public function urlLoadEvent(urlL:String):void { super(URL_CHANGED); urlLocation = urlL; trace(urlLocation); } } } -- I'm not sure where to attach this. ???.addEventListener(urlLoadEvent.URL_CHANGED, onURLChange); ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Custom eventListener
I use custom events mostly when I have data to pass through the event which doesn't fit nicely into some pre-defined one. For instance, we have a HighScoreEvent which has the number of points and the time it took to finish the game. Also, it is good practice to define your own Event subclass(es) to contain the names of the events. Otherwise you are left with this kind of thing: addEventListener( injury, onInjury ); dispatchEvent( new Event( Injury )); And you have a bug caused by a spelling error. If instead you do this: addEventListener( InjuryEvent.INJURY, onInjury ); dispatchEvent( new InjuryEvent( InjuryEvent.lNJURY )); The compiler will catch the spelling error for you. Dave On 12/18/08, Cor c...@chello.nl wrote: Jason: This is all simplified, advanced coders would use some design patterns or frameworks to handle all this, but you get the idea. Maybe I am slow... or even dumb? But all those things I can do with normal events, I guess. So what I mean was an example of something you cannot do with normal event or what is specific case for using a custom event? Kind regards Cor ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Re: A funny little hover problem with CSS
We had a similar issue triggered by scaling. When we rescaled objects with Advanced Anti-Aliasing text, they wouldn't recompute their size properly and would truncate themselves with ... at the end at some scales but not at others. We ended up just turning it off. It's true that it looks better, but if it doesn't work, it doesn't work. :-/ Dave On 12/14/08, Ashim D'Silva as...@therandomlines.com wrote: Right. I recreated everything slowly in a new file, introducing things one by one and here's the culprit - Advanced Anti-Aliasing.Now I really would like to use advanced, because text looks dramatically better, but there has to be a solution, doesn't there? 2008/12/15 Ashim D'Silva as...@therandomlines.com Hi all, I'm having a really odd problem, that I haven't been able to find anything about. I have a multiline, word wrapped TextField that uses CSS (built as objects), with content coming from HTML in an XML file. It all works fine, but for some reason, when I hover over a link (whether I have CSS for hover or not) it moves a pixel or two. Sometimes only the first time, sometimes all the time. If I have a a:hover in the CSS it definitely moves every time. Has anyone encountered this, got a solution or have any idea why this would happen? Thanks, Ashim -- The Random Lines My online portfolio www.therandomlines.com -- The Random Lines My online portfolio www.therandomlines.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] binary-coded image
Also Flex supports PNG and JPEG: mx.graphics.codec.PNGEncoder and mx.graphics.code.JPEGEncoder. Dave On 12/3/08, Ian Thomas [EMAIL PROTECTED] wrote: If you mean 'how do I encode a bitmap into an image format' e.g. PNG or JPEG, check out this library: http://code.google.com/p/as3corelib/wiki/Main which has code for both PNG and JPEG. HTH, Ian On 12/3/08, laurent [EMAIL PROTECTED] wrote: Hi, How could I convert a bitmap to a binary-coded bitmap ... or anything else that will represent a binary-coded image ? Thanks L ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] adding physics to pivot object around a point
http://box2dflash.sourceforge.net/ Good stuff. Dave On 12/1/08, allandt bik-elliott (thefieldcomic.com) [EMAIL PROTECTED] wrote: hi guys could anyone point me in the right direction to do the following, please? I'd like an object that is dragged to correctly respond to being pulled around by pivoting around the point it is dragged by (also applying downward force to represent gravity) for example, if i hold a pencil lightly at one end, it will pivot around the point i am holding and swing until it comes to a rest pointing straight down. does anyone know of any tutorials that go into this kind of thing? thanks for your help a ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] passing on ... args
Ooh! Ooh! I just wrote this a few days before you asked. Here's my solution: public function call( rpcName: String, responder: Responder, rpcArgs: Array ): void { // NetConnection.call() takes a variable number of arguments after the // RPC call name and the responder. To make a pass-through call from // one such function (this function) to another (NetConnection.call()), // we must make an array of ALL arguments to the target function and // then call apply() on the Function object we wish to call (_nc.call). var callArgs: Array = [rpcName, responder].concat( rpcArgs ); // Function.apply() also wants a this reference, so we pass _nc in too. _nc.call.apply( _nc, callArgs ); } As Meinte says, it isn't worth the mess, so I don't use ... in my own code. The contents of the function would look exactly the same if you changed the call signature to match NetConnection's: public function call( rpcName: String, responder: Responder, ... rpcArgs ): void And then it's a proper pass-through. With Latcho's example: testargs( a,b,{z:'zz'},[1,2,3],c ) private function testargs(... argsA):void { trace(#args_A:, argsA.length)/// traces: #args_A: 5 passingArgs.apply(this, argsA) } public function passingArgs(... argsB):void { trace(#args_B:,argsB.length) /// traces: #args_B: 5 for(var i:int=0;iargsB.length;i++) { trace(argsB[i]); } }; If passingArgs() isn't a member function of some class, I'm not sure what you pass as apply()'s first argument, possibly null? Dave On 11/28/08, Meinte van't Kruis [EMAIL PROTECTED] wrote: I think I tried something with casting to array or using Function.apply, I'm pretty sureFunction.apply or call does the trick after messing around with it I decided it wasnt worth the mess and used array's instead.. On Fri, Nov 28, 2008 at 4:18 PM, Latcho [EMAIL PROTECTED] wrote: Hi List, How can I pass a variable amount off function arguments to a next function ? Below the way I tried and which fails. While passing them they get combined I'd like to remain 5 variables for args_B and not a single string. Stijn CODE: testargs( a,b,{z:'zz'},[1,2,3],c ) private function testargs(... argsA):void { trace(#args_A:, argsA.length)/// traces: #args_A: 5 passingArgs(argsA) } public function passingArgs(... argsB):void { trace(#args_B:,argsB.length) /// traces: #args_B: 1for(var i:int=0;iargsB.length;i++) { trace(argsB[i]); } // which traces a string: a,b,[object Object],1,2,3,c }; Latcho ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- M.A. van't Kruis http://www.malatze.nl/ ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] frameworks and flash
Actually, Cairngorm does allow arbitrary mappings from events to commands, it does not require 1-to-1. The FrontController's addCommand() function takes an event name (String) and a Command class. In our app I have used the same event with different name-constants to run different commands, like so: addCommand(FollowingEvent.ADD, AddFollowingCommand); addCommand(FollowingEvent.REMOVE, RemoveFollowingCommand); In the constructor of FollowingEvent I take a type (String) parameter which I pass through to CairngormEvent's constructor. Dave And one more thing I dislike is the 1 on 1 mapping of Events and Commands. From what I've seen in their docs and samples they use a different Event class for every Command, which IMO makes no sense. GetUserEvent UpdateUserEvent DeleteUserEvent CreateUserEvent And the static constants are stored someplace else, can't remember but think it was the Controller (that extends FrontController). Rather than having 4 Event classes for each Command I prefer 1 Event class: UserEvent which has as many static constants as required: public static const GET_USER:String = getUser; public static const UPATE_USER:String = updateUser; public static const DELETE_USER:String = deleteUser; public static const CREATE_USER:String = createUser; Again this is inline with what is already present in the Flex framework: MouseEvent.CLICK MouseEvent.MOUSE_DOWN MouseEvent.MOUSE_UP etc.. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] get class by definition - or something like that
You want ApplicationDomain.getDefinition(className: String) and also ApplicationDomain.hasDefinition(className: String) is handy. Dave On Thu, Nov 20, 2008 at 1:52 PM, Merrill, Jason [EMAIL PROTECTED] wrote: Refersh my memory. What was the name of that AS3 class method to get a class definition from a string? Something like getObjectByDefinition(MyClass) or something like that, but that's not it. Our proxy server is down and I can't Google it, and the help docs are no help. Basically, I'm tring to remember the AS3 method to dynamically instantiate a class from a string definition - i.e. var ClassDefinition:Class = getClassByDefinition(Apple); var newClassInstance:* = new ClassDefinition(); Something like that, I've done it before, I just can't find the syntax or remember the method. Jason Merrill Bank of America Instructional Technology Media ยท GCIB Staff Support LLD Interested in Flash Platform technologies? Join the Bank of America Flash Platform Developer Community Interested in innovative ideas in Learning? Check out the Innovative Learning Blog and subscribe. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Flex vs. Flash
If you are building an application-like user interface with buttons, forms, dialog boxes, etc, I would really recommend Flex. MXML lets you write such things very concisely. It has a powerful layout engine and a nice set of containers which automate a lot of stuff you'd have to write by hand otherwise. If your program is mostly animation and graphics, I guess Flex wouldn't have a lot to offer. Flex is certainly a big chunk to add to your binary size, so I wouldn't choose it lightly. We wrote playcrafter.com in Flex and have no regrets about the choice. You can certainly write anything in plain AS3 that you can write in MXML with the Flex library. You just need to decide if the code in the Flex library is code you'd need to be writing anyway. Dave On Wed, Nov 19, 2008 at 10:25 AM, Lehr, Ross (N-SGIS) [EMAIL PROTECTED]wrote: I guess this is somewhat off topic, but I'm new to the whole Flex thing. What are some of the reasons one would build something in Flex instead of Flash? Is it just a preference thing, or are there real technical reasons one should build a particular app in Flex? Thanks ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] frameworks and flash
We have been using Adobe Flex for the past year and have really liked it. It would be hard to call it blazing and bloat does seem like it might apply to some extent, but on the other hand it does so many nice things for us it is hard to argue with. MXML is very powerful, but there is certainly a big learning curve. For basic stuff, buttons and containers and text, it's easy to get started. There are lots of subtle details though, so when you start wanting to do things in ways the Flex authors didn't anticipate it often takes experimentation to find a way that works. The Flex framework code is open source at least, so you can always dig into that and see what it's doing. We have also used Cairngorm, with mixed results. Cairngorm doesn't really give you much code, it is mostly a set of design patterns. Some of the important code it does give is a controller which connects Cairngorm Events to Cairngorm Commands. Cairngorm events inherently know their dispatcher, which is a singleton, so you can just fire off events like so: new SaveGameEvent(game, user).dispatch(); and the controller connects that to the appropriate SaveGameCommand. We've come to the conclusion that Cairngorm is great for situations where most user actions imply immediate communications with a server, but not so useful for situations where user actions are just manipulating data internal to the .swf. We have ended up using Cairngorm Events and Commands just on the networking side of our app, and for everything else we do more of a basic Model/View pattern. I don't believe Cairngorm relies on Flex, but Flex gives you data binding which works very nicely with Cairngorm. Flex data binding lets you mark certain state variables with [Bindable] and then the compiler builds data-change events for you. Then your view mxml classes use the data binding syntax like Label text={game.description}/ and the view updates automagically whenever the Game's description field changes. A Cairngorm command might query a server and then the server-response-handler in the command can set game.description. Dave On 11/14/08, Joel Stransky [EMAIL PROTECTED] wrote: Hello, So I'm trying to nail down a work flow for building flash sites (read: not flash applications) in as3. I had just about mastered fast seo friendly as2 sites when as3 came out and now that I'm making a concerted effort to modernize my skills I feel like I'm starting from scratch in many ways. Enter frameworks. So far I've looked at Gaiahttp://www.gaiaflashframework.com/index.php, PureMVC http://puremvc.org/content/view/67/178/, Matehttp://mate.asfusion.com/and Enterprise Architect http://www.sparxsystems.com/products/ea/index.html (please add any others I haven't listed) On the upside, I like the idea of rapid development and reduced monotony. But the most important thing to me is extremely lightweight blazing fast flash using the least amount of bloat. In a perfect scenario, I don't want extra file size due to wrappers of core commands. So, assuming I'm comfortable with the file size/rapid development trade off with one of these packages, my concern then becomes one of dependency and learning curve. After learning a new API, am I going to have to hack or work around it for those interesting situations that always seem to pop up? What if something major changes on the flashplayer and my chosen framework doesn't address it? I fear becoming too dependent on a 3rd party api. I'd really like to know what you guys are using, any development horror stories you have because of it as well as any insight you can provide about the concerns I've listed. Thanks for your time. -- --Joel Stransky stranskydesign.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] frameworks and flash
Haha! Before you try Cairngorm, check out this article: http://blog.iconara.net/2008/04/13/architectural-atrocities-part-x-cairngorms-model-locator-pattern/ Having used Cairngorm for a while now I have to agree with him. The article is pretty harsh, and it only talks about the ModelLocator part. Dave On 11/14/08, Joel Stransky [EMAIL PROTECTED] wrote: Thanks for the post Dave. Cairngorm sounds a lot like PureMVC which does away with events and implements a global command structure. So far it's appealing although my first run in with it was under bad conditions. A client of a friend had mangled it something fierce before he was brought in at which point he brought me in to implement deep linking. It was ugly to say the least. I have however heard great things about it since then. My gut says I should know how to do this stuff on my own before I go relying too heavily on tools that prevent me from getting to know the inner workings intimately. It's just tough to esitmate flash/flex work effictively anymore without a framework involved it seems. Clients don't have the time or budget for builds from scratch. Flash used to be so fun but now it's a constant learning curve. ugg. Interestingly enough I looked up the cairngorm site and saw a link to this blog post made just yesterday: http://www.anandvardhan.com/2008/11/13/popular-flex-frameworks/ This should also be informative. http://www.insideria.com/2008/11/new-poll-which-flex-framework.html On Fri, Nov 14, 2008 at 1:52 PM, David Hershberger [EMAIL PROTECTED] wrote: We have been using Adobe Flex for the past year and have really liked it. It would be hard to call it blazing and bloat does seem like it might apply to some extent, but on the other hand it does so many nice things for us it is hard to argue with. MXML is very powerful, but there is certainly a big learning curve. For basic stuff, buttons and containers and text, it's easy to get started. There are lots of subtle details though, so when you start wanting to do things in ways the Flex authors didn't anticipate it often takes experimentation to find a way that works. The Flex framework code is open source at least, so you can always dig into that and see what it's doing. We have also used Cairngorm, with mixed results. Cairngorm doesn't really give you much code, it is mostly a set of design patterns. Some of the important code it does give is a controller which connects Cairngorm Events to Cairngorm Commands. Cairngorm events inherently know their dispatcher, which is a singleton, so you can just fire off events like so: new SaveGameEvent(game, user).dispatch(); and the controller connects that to the appropriate SaveGameCommand. We've come to the conclusion that Cairngorm is great for situations where most user actions imply immediate communications with a server, but not so useful for situations where user actions are just manipulating data internal to the .swf. We have ended up using Cairngorm Events and Commands just on the networking side of our app, and for everything else we do more of a basic Model/View pattern. I don't believe Cairngorm relies on Flex, but Flex gives you data binding which works very nicely with Cairngorm. Flex data binding lets you mark certain state variables with [Bindable] and then the compiler builds data-change events for you. Then your view mxml classes use the data binding syntax like Label text={game.description}/ and the view updates automagically whenever the Game's description field changes. A Cairngorm command might query a server and then the server-response-handler in the command can set game.description. Dave On 11/14/08, Joel Stransky [EMAIL PROTECTED] wrote: Hello, So I'm trying to nail down a work flow for building flash sites (read: not flash applications) in as3. I had just about mastered fast seo friendly as2 sites when as3 came out and now that I'm making a concerted effort to modernize my skills I feel like I'm starting from scratch in many ways. Enter frameworks. So far I've looked at Gaiahttp://www.gaiaflashframework.com/index.php, PureMVC http://puremvc.org/content/view/67/178/, Matehttp://mate.asfusion.com/and Enterprise Architect http://www.sparxsystems.com/products/ea/index.html (please add any others I haven't listed) On the upside, I like the idea of rapid development and reduced monotony. But the most important thing to me is extremely lightweight blazing fast flash using the least amount of bloat. In a perfect scenario, I don't want extra file size due to wrappers of core commands. So, assuming I'm comfortable with the file size/rapid development trade off with one of these packages, my concern then becomes one of dependency and learning curve. After learning a new API, am I going to have to hack or work around
[Flashcoders] AS3 text fitting in variable box
No problem. A binary search is an order log(N) method for finding something in an ordered list of elements, as compared to linear search, which is order N. (N is the number of elements, in this case, font sizes you are willing to use.) You have a sequence of font sizes. For each size, it either makes the TextField too tall, or it doesn't. You want to find the biggest size which isn't too tall. The linear approach is to start from one end of the font size list or the other and try sizes one by one until the TextField height crosses the threshold. The binary approach is to try both ends first, say 1 and 50. If 1 is too big or 50 is too small, you already have your answer. If not, try the middle: 25. If 25 is too big, move your idea of biggest down to 25, and try the middle between 25 and 1: 13. Maybe 13 is too small, so change your idea of smallest to 13. Then try the middle between 13 and 25: 19, and so on. Once the two ends (smallest and biggest) are adjacent elements (say one point difference in font size), the one marked smallest is your answer. Binary search is only a little more complicated than a linear search to implement, and if you are searching over a large number of font sizes, the savings can be significant. If it's just 4 or 5 font sizes it's probably not worth the trouble. Binary search is a very classic computer science algorithm, so I'm sure you can find good descriptions on the web. Dave On 11/12/08, Latcho [EMAIL PROTECTED] wrote: Hi Joel, Jonathan anf Dave for your answers Dave could you explain what you mean with a binary search ? Stijn David Hershberger wrote: Text flow of variable-width fonts with word-wrapping is inherently messy... there's no way to compute the number of lines with some nice math, you just have to run the text-flow machinery and measure the result, which is exactly what you have suggested. I'm pretty certain there is nothing built into flash or flex to choose a font size for you automatically. My only suggestion is a speed optimization: use a binary search instead of trying every font size. Dave On 11/12/08, Latcho [EMAIL PROTECTED] wrote: I'm talking about font size, not stretching a container. Increasing / decreasing font size to get an optimal fill of a box which will have a fixed width and a certain height which can only be determined during load time. I could increase the font size of a textfield in a loop and measure it's height on every point increase; when it overflows my wanted box-height I take the font size of the previous step. Is there an easier way ? Stijn Joel Stransky wrote: Sounds like a bad design decision to make titles of the same category various sizes. But I think you can just set the .width property, then set the .scaleY equal to the .scaleX or visa versa depending on which dimension is more important. On Wed, Nov 12, 2008 at 9:40 AM, Latcho [EMAIL PROTECTED] mailto: [EMAIL PROTECTED] wrote: I need to place project-titles in a multiline textfield, wherof the width will be fixed, but sometimes this box might be of less height because of more space used by other displaying project elements. Is there a class that can dynamically regulate the font it's size to fit the loaded text to a certian textfield height of a multile textfield? The project titles are variable in character word length. How is this solvable. Thanks ! Stijn ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com mailto:Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- --Joel ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] AS3 text fitting in variable box
Text flow of variable-width fonts with word-wrapping is inherently messy... there's no way to compute the number of lines with some nice math, you just have to run the text-flow machinery and measure the result, which is exactly what you have suggested. I'm pretty certain there is nothing built into flash or flex to choose a font size for you automatically. My only suggestion is a speed optimization: use a binary search instead of trying every font size. Dave On 11/12/08, Latcho [EMAIL PROTECTED] wrote: I'm talking about font size, not stretching a container. Increasing / decreasing font size to get an optimal fill of a box which will have a fixed width and a certain height which can only be determined during load time. I could increase the font size of a textfield in a loop and measure it's height on every point increase; when it overflows my wanted box-height I take the font size of the previous step. Is there an easier way ? Stijn Joel Stransky wrote: Sounds like a bad design decision to make titles of the same category various sizes. But I think you can just set the .width property, then set the .scaleY equal to the .scaleX or visa versa depending on which dimension is more important. On Wed, Nov 12, 2008 at 9:40 AM, Latcho [EMAIL PROTECTED] mailto: [EMAIL PROTECTED] wrote: I need to place project-titles in a multiline textfield, wherof the width will be fixed, but sometimes this box might be of less height because of more space used by other displaying project elements. Is there a class that can dynamically regulate the font it's size to fit the loaded text to a certian textfield height of a multile textfield? The project titles are variable in character word length. How is this solvable. Thanks ! Stijn ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com mailto:Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- --Joel ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] keyboard focus mouse button interaction
Hi all, I ran into an issue with keyboard focus which I don't understand, and I don't see detailed in the docs anywhere. We have a site that has games in it as well as forms, so sometimes we want game-style key handling and sometimes we want the form style, where tab or mouse clicks change focus. In many of our games you need to use the keyboard and mouse, and it seems as though every time the mouse button is pressed inside our game area (a Flex Canvas), stage.focus gets set to null, so the keyboard event listeners attached to our Canvas don't get called. My current hack to fix it is to listen for FOCUS_OUT events from the Canvas and set stage.focus back to the Canvas. That seems to work, but I wonder: 1) why Flash (or Flex?) is setting stage.focus to null when I click on my game Canvas, and 2) how to make a component (my game Canvas) such that I can programmatically set it to be focused or unfocused and disable the mouse button -based focus change. It seems funny that I have to keep re-asserting the focus. I tried listening for MOUSE_FOCUS_CHANGE events and cancelling the default action of them, but those events did not fire when the focus was changed to null. Strange. Another factor is that sometimes our games are loaded from other .swf files, and then the game Canvas can't access the stage because it would be a sandbox violation. So it seems like I can't just attach my game key listeners to the stage directly. In fact this makes me wonder if my stage.focus thing isn't going to fail as well... I suspect I need to make my game canvas implement IFocusManagerComponent or something, but before I spent too much time experimenting I wanted to see if anyone already knew the Right Way to handle this. Thanks, Dave ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders