Hello, I have a working code with working sprites. But I'm trying to figure out how to make him stop moving when i don't hold down the key. Here is the code:
bad gab, bad! (jk) - you should steer away from using _root, there are lots of reasons, but the main one is that if you load the file into another, like a preloader or a third party service API like Mochi, then _root will point at the 'stage' of the loader, and your code will mostly likely 'break'
instead use: _parent when necessary, or _parent._parent._parent - if you have that many levels to reach back
well M - it really depends on the structure you are using - you can see in the example that i have added 15px to the y values as needed - so you'll need it in your hitTest, and in assignments to 'where' to set the player
so, you can use a 'number' or you can use a property - for instance:
var offsetY:Number = 15; OR var offsetY:Number = hero._height / 2;
Uh? Does _parent just get the nearest level? Cuz in that case is amazing, I wish I knew it before. _root looked so cool, you keep destroying my coding idols
PS how does that ground.hitTest works? Usually when I try to do that it says me "the property is missing the static attribute" or something like that. Did you set a static property in some way?
@plasmafish - yes it seems the OP is building a basic platformer, but the questions in this thread are related to refining the systems needed to do so and learning about them and i have previously posted an example fla and it's code - you're example could clearly benefit from some of the discussion here, and does not assist the OP because you have not provided any code, thoughts or theory, only a compiled swf file.
@gab - sorry bud LOL - yeah the use of root can really cause issue, but it's commonplace when first getting going and is found all over in tutorials even - so no worries
_parent) sort of, when you create a MC, and then place another MC 'inside' the first, it is known as a 'child' of the 'arent' clip - each time you do so, it becomes a child of the clip you place it into. so you can do this with many levels, for instance:
lets build a rocket, on the rocket's timeline it has nose, body, wings, engine - all clips - the engine's timeline has a cone, and flames. now to call from the main timeline to get to the flames to 'turn them on' we'd use the path: rocket.engine.flames - you can see by the syntax that the flames are 3 'levels' deep - the flames are a 'child' of the 'engine' the engine is a child of rocket, and rocket is ultimately a child of the main timeline or stage. so to transverse the display stack in the 'other' direction, from the flames instance to the stage we have to iterate through as many levels as needed to get there, store a ref to the stage or use a short-cut like root (but still bad to do so) so if we have a call that in the flames instance that needs to get to the stage, one way to do it is to use:
there are other more efficient ways of doing this though, especially within a Class structured framework - but this is the core principle of parenting hierarchy.
gab - about the hitTest issue: not certain unless i was view specific code - statics are a hot topic of Class structures and Deisgn Patterns these days, as opposed to using the getter/setter mindset (i prefer statics atm)
it's possible that you'd missed an instance name and we're running into a 1120 null object reference, or were calling the method outside the scope of an instance (like from 'inside' another instance, that does not have a reference to the 'name' of the other) - or perhaps you had missed one of the parameters when using a 'shapeflag' based hitTest, which requires three arguments
in as2 outside a class file, on a timeline the property declarations are 'local' to the scope in which they are created, as is the case for any property declared within another Object (including methods, or 'functions'
I'll try to explain that better. When I try to refer to a thing in a class I have to make _parent or _root or whatever, but I saw that you just wrote ground, so I thought you were referring to a class, but in as2 I can never do it, it says me the static thing. So, first, was you referring to the class or the instance?
Beech, I didn't want to give an FLA because I don't know what hes aiming for. I'm just assuming that at this speed, it will take him years to make a half working game.