Re: [Flashcoders] top down plane games
So I've been playing around with it some more and been getting a little closer. But its still a ways off. The biggest issue with this demo is that the plane catches the mouse before I reach the edges of the map. I'm not sure what I can do next but thats where I am now. Its funny to. About 20 mins after I posted this I decided to bite the bullet and buy Keith's book. I'm going to open it tonight and see where it gets me. If you guys have any more ideas please let me know! Thanks! What I've come up with so far is something like this... var speed:Number = 2; var turnRate:Number = .3; var agroRange:Number = 500; var moveX:Number = 0; var moveY:Number = 0; var distanceTotal:Number; //stage vars var minXMove:Number = 0; var minYMove:Number = 0; var maxXMove:Number = (levelMap.width - stage.stageWidth) * -1; var maxYMove:Number = (levelMap.height - stage.stageHeight) * -1; function movemap():void { //move on x-axis levelMap.x -= (moveX * 2); if (levelMap.x >= minXMove) { levelMap.x = minXMove; //speedX *= -1; } if (levelMap.x <= maxXMove) { levelMap.x = maxXMove; //speedX *= -1; } //move on y-axis levelMap.y -= (moveY * 2); if (levelMap.y >= minYMove) { levelMap.y = minYMove; //speedY *= -1; } if (levelMap.y <= maxYMove) { levelMap.y = maxYMove; //speedY *= -1; } } stage.addEventListener(Event.ENTER_FRAME, doFollow2); // // doFollow(follower, target) // use ex: doFollow(myEnemyMovieClip, playerMovieClip) // function doFollow(e:Event) { //calculate distance between follower and target var distanceX:Number = mouseX - plane.x; var distanceY:Number = mouseY - plane.y; //get total distance as one number distanceTotal = Math.sqrt((distanceX * distanceX) + (distanceY * distanceY)); //check if target is within agro range if(distanceTotal <= agroRange){ //calculate how much to move var moveDistanceX:Number = turnRate * (distanceX/distanceTotal); var moveDistanceY:Number = turnRate * (distanceY/distanceTotal); //increase current speed moveX += moveDistanceX; moveY += moveDistanceY; //get total move distance var totalmove = Math.sqrt(moveX*moveX+moveY*moveY); //apply easing moveX = speed * (moveX/totalmove); moveY = speed * (moveY/totalmove); //move follower plane.x += moveX; plane.y += moveY; //rotate follower toward target plane.rotation = 180*Math.atan2(moveY, moveX)/Math.PI; movemap(); } } On Mon, Jan 26, 2009 at 1:46 PM, Todd Kerpelman wrote: > Well, again, don't know how much this will help you, but in the past when > I've done a "camera following a moving object with a scrolling background", > I've attached a virtual spring from my camera to the position I want to go > to and then just let the spring drag my camera to the right place. If you > put on some pretty heavy damping, it ends up looking pretty good, and I > don't have to think about angles. :) > > Your spring code would probably look something like this... > > private function onEnterFrame(e:Event):void > { > > var accelX:Number = (_pointToFollow.x - this.x) * _k; > var accelY:Number = (_pointToFollow.y - this.y) * _k; > _velX += accelX; > _velY += accelY; > this.x += _velX; > this.y += _velY; > _velX *= _damping; > _velY *= _damping; > > } > > You probably want _k to be something in the .1 range, and _damping to be in > the .75 range. All of this assumes, by the way, that you're not rotating the > camera to match the rotation of the plane. > > But the book Jason recommended might have better ideas. I haven't read it > yet. > > --T > > > > On Sun, Jan 25, 2009 at 1:15 PM, Corban Baxter 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 { >> >> >
[Flashcoders] Loading image on local filesystem
The AS is in a dir1 (dir1\stuff.as) and the images are in dir1\img\image.jpg. imagePath = new URLRequest(this.imagePathString); loader = new Loader(); trace(loader.load(imagePath)); this.imagePathString is a relative path to the image (img\image.jpg). How can I load these from a local filesystem? This will be moved to a web server but for testing I am running on windows and Flash CS3 in Windows XP as a vm on my laptop in VMWare. Thanks for any help. Kevin ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] instancing my own components (still new to AS3)
> could you put your init() method call in a setter? No :-) Actually, these [Inspectable] parameters and their setters are not a *functional* part of component. I mean that, if it's created via code (using constructor), [Inspectable] parameters are not used. However, if user has the component in Flash IDE and set anything in component properties/inspector, they should work. for now, I found a solution: I put my init() in ENTER_FRAME listener and then remove this listener :-) I just wanted to be sure that there's no solution more elegant than mine > On Wed, Jan 28, 2009 at 10:27 AM, Gregory N wrote: > > > Yes, as allandt suggests, you should provide a default value for > > constructor param > > Unfortunately, it's not the only problem with components (at least in CS3) > > For me, the worst one is about [Inspectable] parameters (and their > > setters). > > As described here > > http://www.bit-101.com/blog/?p=1181 > > setters are called lo-o-ong AFTER constructor > > And, even if I set my init() as listener for ADDED_TO_STAGE event... > > setters > > are not called before it :-( > > > > Any advice to determine the exact time setters are called? > > > > > > On 1/27/09, allandt bik-elliott (thefieldcomic.com) > > wrote: > > > > > > you can put the default value into the parameters in the constructor so: > > > > > > > > > package { > > >import flash.display.MovieClip; > > >import flash.text.*; > > >public class MyButton extends MovieClip{ > > >public var buttonLabel:String; > > > > > >public function MyButton (buttonLabel:String = "GO"){ > > > > > >this.buttonLabel = buttonLabel; > > >btnLabel.text = buttonLabel; > > >} > > >} > > > } > > > -- -- Best regards, GregoryN http://GOusable.com Flash components development. Usability services. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Garbage Collection difficulty
It was my understanding that Garbage Collection doesn't always occur right away. When you have orphaned objects sitting on the heap, they are * eligible* for garbage collection. That doesn't mean they will be removed from memory right away. Especially if you're testing for JUST that to happen. Usually GC occurs when more memory is needed. Someone else could probably speak to this topic much more intelligently than me.. but that was my understanding of how GC in general works. Cheers On Tue, Jan 27, 2009 at 6:04 AM, Sander Schuurman < sander.schuur...@oswaldandruby.com> wrote: > Thnx for the links... tried some, but still with no success... I now have > the following: > > public class Image extends MovieClip > { > private var _thumbLoader:Loader; > private var _largeLoader:Loader; > > private var _thumb:Bitmap; > private var _large:Bitmap; > > public function loadThumb() :void > { > _thumbLoader = new Loader(); > _thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, >thumbLoaded, false, 0, true); > _thumbLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, >errorOccured, false, 0, true); > _thumbLoader.load(new URLRequest(_tu)); > } > > private function thumbLoaded( e :Event ) :void > { > _thumb = Bitmap(e.currentTarget.content); > _thumb.smoothing = true; > > addChild(_thumb); > > _thumbLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, > > thumbLoaded); > _thumbLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, > > errorOccured); > _thumbLoader = null; > > dispatchEvent(new Event(Image.IMG_LOADED)); > } > > public function loadLarge() :void > { > _largeLoader = new Loader(); > _largeLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, >largeLoaded, false, 0, true); > _largeLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, >errorOccured, false, 0, true); > _largeLoader.load(new URLRequest(_lu)); > } > > private function largeLoaded( e :Event ) :void > { > _large = e.currentTarget.content; > _large.smoothing = true; > addChild(_large); > > _largeLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, > > largeLoaded); > _largeLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, > > errorOccured); > //_largeLoader.content.dispose(); > _largeLoader = null; > > dispatchEvent(new Event(Image.IMG_LOADED)); > } > public function disposeLarge() :void > { > if (_large) > { >removeChild(_large); >_large.bitmapData.dispose(); >_large = null; > } > } > > public function dispose() :void > { > disposeLarge(); > > removeChild(_thumb); > _thumb.bitmapData.dispose(); > _thumb = null > } > > } > > Anyone some tips? The large bitmap stays in memory... > > -Original Message- > From: flashcoders-boun...@chattyfig.figleaf.com [mailto: > flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Glen Pike > Sent: Wednesday, 21 January 2009 21:18 > To: Flash Coders List > Subject: Re: [Flashcoders] Garbage Collection difficulty > > Hi, > >I think if you use it locally, you still have to "dispose" of it: > >http://www.bartclaessens.com/tag/memory-management/ > >http://labs.bigspaceship.com/2007/02/28/flash-performance-tips-part-ii/ > >http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html > >Search for "dispose" in some of these - also, one of the comments in > Grant's article mentions testing in the IDE vs testing in the browser > gives different results for loaded images. > >HTH > >Glen > > Sander Schuurman wrote: > > That's a local variable right? Doesn't it happen automatic? > > I must concentrate on the _large Sprite, isn't it? > > > > > > -Original Message- > > From: flashcoders-boun...@chattyfig.figleaf.com [mailto: > flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Glen Pike > > Sent: Wednesday, 21 January 2009 12:20 > > To: Flash Coders List > > Subject: Re: [Flashcoders] Garbage Collection difficulty > > > > Hi, > > > > Do you have to destroy the Bitmap you create in the largeLoaded > > function??? > > > > Glen > > > > Sander Schuurman wrote: > > > >> Hi cool list, > >> > >> I'm struggling with my Image class. It's supposed to load and unload > different sized images dynamicly; but I can't seem to get it to work > properly. The loading works fine, but the unloading not for the full 100%. > It visually unloads the image, but it remains in the memory. I have tried > several different things; I'm a bit stuck now. > >> > >> Here is a stripped class: > >> > >> public class Image extends MovieClip > >> { > >> ... > >> private var _largeLoader:Loader; > >> private var _large:Sprite; > >> ... > >> public function Image( thumbUrl :String, > >> normalUrl > :String, > >>
Re: [Flashcoders] Garbage Collection difficulty
Ah yes... I knew I read it somewhere... It's in that Grant Skinner article. *Deferred GC and Indeterminacy* A *very* important thing to understand about the Garbage Collector in FP9 is that it's operations are deferred. Your objects will not be removed immediately when all active references are deleted, instead they will be removed at some indeterminate time in the future (from a developer standpoint). The GC uses a set of heuristics that look at RAM allocation and the size of the memory stack (among other things) to determine when to run. As a developer, you must accept that fact that you will have no way of knowing when (or even if) your inactive objects will get deallocated. You must also be aware that inactive objects will continue to execute indefinitely (until the GC deallocates it), so code will keep running (ex. enterFrames), sounds will keep playing, loads will keep happening, events will keep firing, etc. It's very important to remember that you have no control over when your objects will be deallocated, so you must make them as inert as possible when you are finished with them. Strategies to manage this will be the focus for a future article. On Wed, Jan 28, 2009 at 8:31 AM, Nate Beck wrote: > It was my understanding that Garbage Collection doesn't always occur right > away. When you have orphaned objects sitting on the heap, they are * > eligible* for garbage collection. That doesn't mean they will be removed > from memory right away. Especially if you're testing for JUST that to > happen. Usually GC occurs when more memory is needed. > > Someone else could probably speak to this topic much more intelligently > than me.. but that was my understanding of how GC in general works. > > Cheers > > On Tue, Jan 27, 2009 at 6:04 AM, Sander Schuurman < > sander.schuur...@oswaldandruby.com> wrote: > >> Thnx for the links... tried some, but still with no success... I now have >> the following: >> >> public class Image extends MovieClip >> { >> private var _thumbLoader:Loader; >> private var _largeLoader:Loader; >> >> private var _thumb:Bitmap; >> private var _large:Bitmap; >> >> public function loadThumb() :void >> { >> _thumbLoader = new Loader(); >> _thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, >>thumbLoaded, false, 0, true); >> _thumbLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, >>errorOccured, false, 0, true); >> _thumbLoader.load(new URLRequest(_tu)); >> } >> >> private function thumbLoaded( e :Event ) :void >> { >> _thumb = Bitmap(e.currentTarget.content); >> _thumb.smoothing = true; >> >> addChild(_thumb); >> >> _thumbLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, >> >> thumbLoaded); >> _thumbLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, >> >> errorOccured); >> _thumbLoader = null; >> >> dispatchEvent(new Event(Image.IMG_LOADED)); >> } >> >> public function loadLarge() :void >> { >> _largeLoader = new Loader(); >> _largeLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, >>largeLoaded, false, 0, true); >> _largeLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, >>errorOccured, false, 0, true); >> _largeLoader.load(new URLRequest(_lu)); >> } >> >> private function largeLoaded( e :Event ) :void >> { >> _large = e.currentTarget.content; >> _large.smoothing = true; >> addChild(_large); >> >> _largeLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, >> >> largeLoaded); >> _largeLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, >> >> errorOccured); >> //_largeLoader.content.dispose(); >> _largeLoader = null; >> >> dispatchEvent(new Event(Image.IMG_LOADED)); >> } >> public function disposeLarge() :void >> { >> if (_large) >> { >>removeChild(_large); >>_large.bitmapData.dispose(); >>_large = null; >> } >> } >> >> public function dispose() :void >> { >> disposeLarge(); >> >> removeChild(_thumb); >> _thumb.bitmapData.dispose(); >> _thumb = null >> } >> >> } >> >> Anyone some tips? The large bitmap stays in memory... >> >> -Original Message- >> From: flashcoders-boun...@chattyfig.figleaf.com [mailto: >> flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Glen Pike >> Sent: Wednesday, 21 January 2009 21:18 >> To: Flash Coders List >> Subject: Re: [Flashcoders] Garbage Collection difficulty >> >> Hi, >> >>I think if you use it locally, you still have to "dispose" of it: >> >>http://www.bartclaessens.com/tag/memory-management/ >> >> >> http://labs.bigspaceship.com/2007/02/28/flash-performance-tips-part-ii/ >> >>http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html >> >>Search for "dispose" in some of these - also, one of the comments in >> Grant's article mentions testing in the IDE vs testing in the browser >> give
RE: [Flashcoders] inserting an MC in a TextField (and speaking to it)
Interesting, I'll have to give it a whirl. Thanks. Regards, -Keith http://keithreinfeld.home.comcast.net > -Original Message- > From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders- > boun...@chattyfig.figleaf.com] On Behalf Of Matt S. > Sent: Wednesday, January 28, 2009 6:41 AM > To: Flash Coders List > Subject: Re: [Flashcoders] inserting an MC in a TextField (and speaking to > it) > > It did work, actually, in terms of inserting it into the TextField, i > guess because the class name effectively functions as the Library > identifier. However, your tip regarding "ID" did the trick for > communicating with it, since I still couldnt modify it, the way I had > it. :) > > thanks, > > .matt ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] instancing my own components (still new to AS3)
could you put your init() method call in a setter? On Wed, Jan 28, 2009 at 10:27 AM, Gregory N wrote: > Yes, as allandt suggests, you should provide a default value for > constructor param > Unfortunately, it's not the only problem with components (at least in CS3) > For me, the worst one is about [Inspectable] parameters (and their > setters). > As described here > http://www.bit-101.com/blog/?p=1181 > setters are called lo-o-ong AFTER constructor > And, even if I set my init() as listener for ADDED_TO_STAGE event... > setters > are not called before it :-( > > Any advice to determine the exact time setters are called? > > > On 1/27/09, allandt bik-elliott (thefieldcomic.com) > wrote: > > > > you can put the default value into the parameters in the constructor so: > > > > > > package { > >import flash.display.MovieClip; > >import flash.text.*; > >public class MyButton extends MovieClip{ > >public var buttonLabel:String; > > > >public function MyButton (buttonLabel:String = "GO"){ > > > >this.buttonLabel = buttonLabel; > >btnLabel.text = buttonLabel; > >} > >} > > } > > > > > > a > > > > > > On Tue, Jan 27, 2009 at 2:26 PM, Mendelsohn, Michael < > > michael.mendels...@fmglobal.com> wrote: > > > > > Hi list... > > > > > > What exactly is the AS3 equivalent of making a simple component, > > > creating a component definition, and attachMovie with the {} holding > the > > > params? > > > > > > I can't get this to work: > > > > > > package { > > >import flash.display.MovieClip; > > >import flash.text.*; > > >public class MyButton extends MovieClip{ > > >public var buttonLabel:String; > > >public function MyButton (buttonLabel:String){ > > >this.buttonLabel = buttonLabel; > > >btnLabel.text = buttonLabel; > > >} > > >} > > > } > > > > > > The component definition has one parameter: > > > Var: buttonLabel, default value:"Go", type:list > > > > > > I'm trying to instance a movie clip that contains instances of this > > > variable. I get various compiler errors when that parent clip is on > the > > > stage. > > > Argument Error 1063 (Argument Count Mismatch) expected 1, got 0, when > > > instancing a movieclip that contains these components. But in parent > > > movie clip, I am setting the params on the stage. > > > > > > 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 > > > > > > -- > -- > Best regards, > GregoryN > > http://GOusable.com > Flash components development. > Usability services. > ___ > 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] inserting an MC in a TextField (and speaking to it)
It did work, actually, in terms of inserting it into the TextField, i guess because the class name effectively functions as the Library identifier. However, your tip regarding "ID" did the trick for communicating with it, since I still couldnt modify it, the way I had it. :) thanks, .matt On Wed, Jan 28, 2009 at 12:31 AM, Keith Reinfeld wrote: > Matt, > > I s'pose I focused too much on the second part of your question in my > previous message. So anyway, if this > >> src='com.myclasses.DropCap' > > actually works then more power to ya! > > If not: > > ActionScript 3.0 Language and Components Reference: > > src: Specifies the URL to an image or SWF file, or the linkage identifier > for a movie clip symbol in the library. > > So, if you have a movieclip in your library with a linkage identifier of > 'DropCap' (associated with a class 'com.myclasses.DropCap') you would use: > > var tString:String = " style='padding:0px;margin:0px'/>Lorem ipsom yadda yadda..."; > myTextField.htmlText = tString; > myTextField.DC0.txt.text = "Z"; > > > Regards, > > -Keith > http://keithreinfeld.home.comcast.net > > > > > ___ > 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] instancing my own components (still new to AS3)
Yes, as allandt suggests, you should provide a default value for constructor param Unfortunately, it's not the only problem with components (at least in CS3) For me, the worst one is about [Inspectable] parameters (and their setters). As described here http://www.bit-101.com/blog/?p=1181 setters are called lo-o-ong AFTER constructor And, even if I set my init() as listener for ADDED_TO_STAGE event... setters are not called before it :-( Any advice to determine the exact time setters are called? On 1/27/09, allandt bik-elliott (thefieldcomic.com) wrote: > > you can put the default value into the parameters in the constructor so: > > > package { >import flash.display.MovieClip; >import flash.text.*; >public class MyButton extends MovieClip{ >public var buttonLabel:String; > >public function MyButton (buttonLabel:String = "GO"){ > >this.buttonLabel = buttonLabel; >btnLabel.text = buttonLabel; >} >} > } > > > a > > > On Tue, Jan 27, 2009 at 2:26 PM, Mendelsohn, Michael < > michael.mendels...@fmglobal.com> wrote: > > > Hi list... > > > > What exactly is the AS3 equivalent of making a simple component, > > creating a component definition, and attachMovie with the {} holding the > > params? > > > > I can't get this to work: > > > > package { > >import flash.display.MovieClip; > >import flash.text.*; > >public class MyButton extends MovieClip{ > >public var buttonLabel:String; > >public function MyButton (buttonLabel:String){ > >this.buttonLabel = buttonLabel; > >btnLabel.text = buttonLabel; > >} > >} > > } > > > > The component definition has one parameter: > > Var: buttonLabel, default value:"Go", type:list > > > > I'm trying to instance a movie clip that contains instances of this > > variable. I get various compiler errors when that parent clip is on the > > stage. > > Argument Error 1063 (Argument Count Mismatch) expected 1, got 0, when > > instancing a movieclip that contains these components. But in parent > > movie clip, I am setting the params on the stage. > > > > 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 > -- -- Best regards, GregoryN http://GOusable.com Flash components development. Usability services. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders