Declaring Stage Elements
We created our first TextFiled on the display but the flash editor wasn't smart enough to know what we actually put on the stage. Let's see how we can tell the flash editor what is on the stage so we can get the fun code hints. declare stage instances using our new TextFiled.
Video Transcript
00:00At this point, we already know how to create a new element on the stage.
00:04So far, we've seen only a text field, and we gave it a name, and now we could trace
00:08that name out.
00:09Now, we want to not only trace things out, because what would be the point if we could
00:13only trace the name out?
00:15We want to get into the properties and start moving it around.
00:18For example, I want to go to my text right now, and I just want to move its position.
00:22As soon as the application starts, I want to make sure that it's centered on the stage,
00:26in the middle of the stage, exactly the center of the stage.
00:29How could I do that?
00:30Well, it's not that hard, but before we do that, we want to do one thing.
00:34We want to make sure that we'll get the hints for a text field, so Flash will actually know
00:38that this is a text field, because right now, although Flash could output its text field,
00:43when we try to go and type text hello, and use the dot syntax, which basically the dot
00:49syntax, we've seen it a little bit before, but basically it enables us to see the properties
00:54of that specific object.
00:56We approach the properties of the object using the dot syntax.
01:00Now you can see as I type dot, I'm not getting anything, but I really want to get those hints.
01:05The way I could get those hints is I want to make sure that I define my variable up
01:09in the beginning before my public function main, and this is the first time we actually
01:12step out of our safe zone, which was our function.
01:18We're going to step out of that function, and let's explain why, because the main reason
01:21why is because the property that we're creating now, the variable that we're creating now,
01:26we're actually not really creating the variable, we're just defining the variable.
01:29The variable was created, or the element, or the text field was already created for us,
01:34so it already exists.
01:35All we're trying to do right now is just define in our public settings, we want to make
01:40sure that our, in our class settings, we want to make sure that one of the properties
01:44of our class is that text field, and by giving that property, it's going to enable us to
01:49get more hints, code hints, which will obviously make our lives easier.
01:54But to do that, what I want to do right now is just type var, which was very similar,
01:57or exactly the same way as we've done it before.
01:59So far we've done it only with basic primitives, and we haven't worked yet with more
02:04advanced, we've worked with objects on arrays which were more advanced, but we haven't
02:08really worked with display objects.
02:11So I'm going to create my display object, and I'm going to give it the type of
02:15text field, and the way we type it is uppercase T, text field, uppercase again for field,
02:22and I'm going to type enter.
02:24Now because I'm working in CS5, it's going to automatically add the import lines,
02:29which are import, space, flash, all in underscore dot text, all in underscore dot text
02:37field, camelcased.
02:38All right, and that's all I really had to do to be able to now actually hit properties
02:45of the text hello.
02:47So if I grab that text hello right now, and I just paste it right here, and I add
02:50the dot, it will automatically add all the properties that belong to my text field.
02:55Okay, and we're going to see what those are in just a second right now.
03:01Now before we do that, I just want to make sure that when I run it, I'm not
03:04going to get any compiling errors.
03:05So let's just run our application and just make sure which is a great habit
03:08to do that.
03:09We're going to run our application for a second, and we see that oh, we do have
03:13a compiling error.
03:15And let's see what our compiling error is.
03:17This error 1156 cannot create property text hello on main.
03:23All right.
03:24And that's because we're missing one more thing to be able to do this.
03:28The reason why we can't create the text hello property is because it already exists.
03:32Right.
03:33But if I will just add right now public var, and I run my application one more
03:39time, look what will happen.
03:40I'm not getting the error.
03:42And the reason is, and we haven't really met public, although we've seen it
03:45right here.
03:47What is that public?
03:48And we're going to see it coming up quite a few times.
03:50There's a few different types of ways to define variables when they belong
03:54to a class.
03:55All right.
03:56And in this scenario, we basically want to say that it's public.
03:58It's available to everyone.
04:00And the reason why we want to say that is because anything that's added
04:02on to the stage directly is automatically public flesh already created
04:07that variable.
04:08And if we want to actually define that variable that already was created,
04:11we have to give it the exact same blueprint or exact same rules as Flash
04:16has defined in its timeline.
04:20Now one thing to note, and you want to make sure that when you're working
04:22with your Flash, you're working with the basic publish settings.
04:28And if you just go into the publish settings and you go into Flash,
04:31you're going to see that somewhere here, let's find it, inside of our
04:35settings, Flash, then settings, and you're going to see strict mode is
04:40set to true, warning mode is set to true, automatically declare stage instances.
