02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Creating The Visual Elements

In this video we continue to parse our rss feed and create the visual elements for our language game.

Video Transcript

00:02And if we scroll back up, we'll be able to see
00:05that we're getting our username.
00:07Now username is probably not the right word
00:09because we want to also get this extra info.
00:13We basically want to get rid of everything here, right?
00:15So to do that, I'm just going to tweak the name,
00:18although we could keep the name the way it is,
00:20but I'd prefer just to give it a name,
00:22maybe a little bit more generic than username
00:25because it's user info maybe, info.
00:30Although that's not 100% correct as well,
00:32but at least it won't make us think
00:34that what we want is only that information.
00:37So first of all, we already got our word French.
00:39And if we work with other Twitter accounts,
00:41we'll be able to automatically detect
00:43what the username is.
00:44Only thing is is that we know that by default,
00:47Twitter will add these extra characters
00:50to everything we post inside of our RSS feed.
00:53So I'm just going to add that directly into our user info.
00:56And we could already go ahead and delete our username.
00:59Because we're not going to be using that anymore.
01:02So now if we go back into our for loop,
01:04we could grab our title.
01:05And what do we want to do to our title?
01:07We want to strip out of the title
01:09that new information we collected in the user info.
01:12And the easiest way to do that is using split.
01:15What split does, it basically creates an array.
01:19It creates an array based on whatever string
01:21we put inside of our split command.
01:23And in our split command,
01:24we don't want to put just a regular string.
01:26We want to put the string
01:27that actually is our user information.
01:30What that would do is actually take our title,
01:32which is a string and convert it into an array.
01:35Separating it using our words French.
01:39Now what that would do would actually generate
01:42an array with two positions.
01:44The first position has nothing in it.
01:45It's an empty string.
01:47And the second position would be all the rest.
01:50Now we don't really want an array.
01:51So we're going to join that array back,
01:53which is a command that is connected to our strings,
01:57which is connected to arrays to convert them into strings.
02:00And we could join them together,
02:02and instead of using the default comma,
02:05we want to use nothing.
02:06Basically telling Flash, reconnect that array,
02:10but have no separation, no space between.
02:13Which that would end us out
02:15at not having stuff that we don't want.
02:18Now the next thing that we don't want
02:20is actually our separators.
02:22Well, we do want them,
02:23because we want to create an array
02:24where we could know this is our French side,
02:27this is our English side, right?
02:28That's why we put it there.
02:31So to do that, I could create a variable here locally.
02:36And let's just do that.
02:37So I'm going to create a little variable
02:38just for the sake of making things more clear.
02:41Or even better, you know, let's use it as a constant
02:44because we're always going to use this type.
02:47And you can see that I kind of prepared in advance
02:49when you didn't notice.
02:50I created our split vowel,
02:54which represents our split value,
02:56which is all it really is is just a constant,
02:58which basically tells Flash,
03:00this variable will never change.
03:03Now by default, we like calling constants as all uppercase.
03:07And we know it's a string,
03:08and we're putting exactly the string information
03:10inside of it, but basically by setting it in this way,
03:12we know it's only going to be defined once,
03:15and it's going to be available throughout our class,
03:18because it's a private constant throughout our definition.
03:22All right, so the next step is actually what we want to do
03:25is we want to split our new string that we just got back.
03:28And what do we want to split it at what point?
03:30We want to split it in our split vowel.
03:33Now, if we run our application one more time,
03:35it's not going to look much different,
03:36but there's a little small difference.
03:39Actually, what we're getting back is arrays.
03:41We're not getting string backs anymore.
03:42And by default, like we were saying,
03:45what actually happens when you try to trace out an array,
03:47it actually traces it out
03:49and joins their information together,
03:51putting a comma in between.
03:53And that's basically when we trace it out,
03:55but if we wanted to, we could have joined them
03:57in some other form, but we didn't really want to join them
04:00in any other form, because actually the next step
04:02that we wanted to do is we actually wanted to gain access
04:07to our immediate variables,
04:10our French and our English one.
04:12And to do that, we could access our array,
04:14which as we said, well, now we know we have two positions
04:18in it, position zero, position one.
04:20So the next step, what I'm going to do
04:22is I'm just going to create a variable
04:23to make it easier to work with,
04:24and I'm just going to call it a words,
04:27is actually grab that array.
04:29We just want to grab that array
04:31and assign its value to the trace that we're getting back,
04:33which is basically an array we just never set,
04:36gave it a variable.
04:38So now that we have our array,
04:39we're ready to start creating our elements.
04:41And to create our elements, we're going to use
04:42a new method, and we're going to call it createElement.
04:50And so now we have our copy inside of our array,
04:53and position zero is our French,
04:55and the second parameter will be a color.
04:58And that color is going to,
04:59we're going to use that as a background color
05:00to differentiate between the French word
05:03and the English word.
05:05And I'm just doing the same thing for English.
05:09Next step is going to be to create actually
05:11that createElement method.
05:17We're going to create another private function.
05:20I'm going to call it createElement.
05:22It's going to accept our copy.
05:25And then for second parameters we've been sending,
05:28it's going to accept a color, which will be our integer.
05:33We're going to actually create a sprite,
05:35and that sprite is going to be the container
05:36that would actually will hold all the elements,
05:40all of the details of our element,
05:43which would basically is a background and our copy.
05:47So now that we know we're going to need a copy as well,
05:48let's create that text field.
05:50So we could then put that text field into our sprite.
05:55And just as a side note, as you're working,
05:58if you're working on CS5 or Flex,
06:00automatically Flash is going to import all the packages
06:04that are related to the classes that we're working with.
06:07If you're working with an older version of Flash,
06:10just grab the source file and copy it in
06:12if you don't know where the locations are.
06:16Start assigning the different details of our text field.
06:19I know that my text field's width,
06:21I want it to be 120 pixels.
06:23Because that we kind of want to make sure
06:25that our copy could flow and to do that,
06:26we want to make sure that our copy is set to multi-line
06:29and that it word wraps.
06:32Next step is we want to make sure
06:34that our copy is not selectable.
06:36Because our sprite is going to be
06:38what we're going to be using for selection,
06:39and we don't want the user to now
06:42also get grabbed by the text field.
06:44The next step is actually we're going to set
06:45our text properties, text property.
06:49And we're going to set its value to our copy
06:51that we sent into our create element.
06:54The next step is actually what I want to do
06:56is set a height to my text field,
06:58because we don't want the default height.
07:00What I want to do is I want to go to my text fields,
07:02text height property, which is going to give me
07:04the height of the current text
07:06that I just put into the text field.
07:07And I'm just going to add a buffer of another four pixels.
07:11And that will be my text height.
07:13The next step I want to do is actually
07:14add my text field into my sprite.
07:18Oh, add child.
07:22And I want to add my sprite to the stage.
07:27And if we run our application now,
07:29we should be getting all of our copy
07:31just flush to the top of the screen.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!