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

Errors and Flash

Errors, what are they good for? Well, I'll tell you, let's take a look at how we can take advantage of errors when we want to trigger them.

Video Transcript

00:00Now, let's see how it works.
00:01Now, it's a little bit problematic if we go back into Flash.
00:04We really wouldn't see it.
00:05If I just publish my Flash file, I'm not seeing anything.
00:10The reason why I'm not seeing it, because the Flash isn't
00:13wrapped inside of the HTML.
00:15So we're going to have to test it out in the browser.
00:18So to do that, I'm going to go into the browser.
00:20Let me just go back here, file a new tab.
00:23And in the new tab, we're just going to go and we're
00:25just going to drop in our Flash files.
00:28And we'll see that, oh no, we can't see anything again.
00:31So we're going to solve this with a little bit of a trick, a
00:34little bit of a dirty trick.
00:35And what we're going to do, we're going to force Flash
00:37to generate an error.
00:38And we're going to show you how to generate an error.
00:40Now, one thing that it's important to note is, if
00:43you're running Flash Player, and it's not the Flash
00:46Debugger, then it's not going to work.
00:48How do you know if it's a Flash Debugger?
00:49Just right click on the area of Flash, and you're going
00:52to see Show, Redraw, Regions, and you're
00:53going to see Debugger.
00:55If you don't see that, then you're not running the Flash
00:57Player, the Flash Debugger.
00:59You're going to have to go to Google, search for Flash
01:01Player Debugger, and then just download the latest
01:04Debugger and install it.
01:05That way, you'll be able to see when errors
01:07run in your application.
01:08So for example, if I try to do dot time dot hello, that
01:14doesn't exist, because time doesn't exist.
01:17Then this will be automatically, it will
01:19throw an error, because it's trying to access something
01:21that doesn't exist.
01:22So if I run my application, you'll see that I'm getting
01:24an error.
01:26And if I go into my browser and I refresh, you're going
01:28to see that I'm getting that error.
01:29Again, this way, it enables us, even when we're working on
01:32the browser, to get these errors as they're running,
01:35which is really, really great to have.
01:38You'll see that a lot of sites have quite a lot of
01:39errors when you run this, and it's a great way to see
01:42how you could avoid these stuff.
01:44All right, so back into Flash, we're going to actually
01:46create our own error.
01:47And our error that we're going to create, it's very,
01:49very simple to do.
01:50What we're going to do is we're going to type throw new
01:53error, all lowercase, besides the uppercase, error.
01:57And if you're thinking, why new?
01:59Because error is actually a class.
02:01So we're creating a new instance of that class, and then
02:03we're throwing it as an error.
02:05And this is the default type.
02:06Now, it accepts one parameter, which is a message, or it
02:09could be multiple parameters.
02:11No, it's actually, it accepts that one parameter of the
02:13message, so if you wanted to add a few things,
02:15you'd put a plus.
02:16So for example, if I wanted to say, this is the value
02:22of time plus the value of your time, and then we're just
02:29going to throw this out and generate the error.
02:31Now, even if we run it in Flash now, it's going to
02:33generate an error.
02:34Not only is it going to generate an error, it's going
02:36to say, this is the value of time undefined.
02:39Now, the syntax, as you said, is very simple.
02:41Just throw lowercase new error.
02:43Now, as soon as that happens, that's it.
02:45Our application will be terminated.
02:46It's not going to continue running our code, because
02:49there's nothing that's caching those errors.
02:51We're going to look into that later on in the future.
02:53The errors here is just to help us see in the browser
02:56what's going on.
02:57So what we're going to see later in the future, actually, how
02:59to work more deeply with errors, because they're quite
03:02useful, and sometimes you don't want to generate an
03:04error, sometimes you want to catch them,
03:05but that's off topic.
03:06So if you jump back into our flash bars, and we just click
03:10on our refresh, we'll see that this is the time, this is
03:15the value of time, 12.
03:16So fantastic.
03:17Now we know that we're getting our external content.
03:20We've just crossed through our first barrier.
03:22We already know that we could send external information, and
03:25it's going to go inside of our time instance.
03:28So far, so good.
03:29Now we're definitely stepping in the right direction.

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!