Interface Errors
null
Video Transcript
00:00All right, so let's talk about multiple interfaces.
00:03Multiple interfaces enables us,
00:05although we could not do that
00:07and absolutely cannot do that with inheritance,
00:10in inheritance in ActionScript 3,
00:12you could only inherit from one thing.
00:14That thing could inherit from another thing,
00:16but it's a very linear chain.
00:17So a cat inherited from an animal
00:20and an animal inherited from a movie clip.
00:22And by the way, a movie clip inherited
00:24from something else earlier on as well
00:26in the key chain behind the scenes
00:27that you could discover it through
00:29the ActionScript documentation
00:31or one of our earlier videos on the movie clip.
00:34So we cannot extend the class and say in ActionScript,
00:38we cannot say a cat extends both an animal class
00:42and a touchable element.
00:44We cannot do that.
00:45There's just no capability in that nature.
00:48Now, although we can't do that,
00:50we could definitely have two different interfaces being used.
00:54And that's exactly what we wanna do next.
00:56Now, before we really jump into it,
00:59I wanna take advantage of the fact
01:00that we have a fire here
01:01and I wanna start off a completely new class.
01:04And really, I'm going off the wing right now.
01:06I didn't do any rehearsals.
01:07Let's see what happens.
01:08What I really wanna do is I wanna grab this fire
01:11and whenever it's clicked on,
01:12I want it to disappear from the screen
01:15and reappear right back after a half a second.
01:18We'll keep it relatively simple.
01:21All right, so I'm gonna go back into my code
01:25and I'm gonna open up a new class.
01:27I'm gonna click on New File.
01:30So I'm gonna open up a new class
01:32and I'm gonna call this class again
01:34in our line of com.zero2geek.op.polefirmism
01:38and we'll just call this fire.
01:41I'm gonna click OK and open up this new class.
01:43It's already established, set up.
01:45All that I have left is just to save the file,
01:47which we'll do next.
01:48Let me just delete these extra lines.
01:50And I'm gonna go again, File.
01:52Oops, not find and replace.
01:54File, save.
01:55And I'll locate our folder that we wanna be in,
01:58which is gonna be in our polyfirmism folder.
02:00The file name is correct.
02:02And I'm gonna click on Save.
02:04All right, so again, so we have here our class.
02:06Now our classifier is not gonna extend anything
02:09from an inheritance, but we do want it to extend something.
02:12Let's extend this time the sprite.
02:14So we're gonna use the sprite.
02:16And we definitely wanna, oh,
02:17we wanna type extends sprite.
02:21All right, so it's gonna automatically import
02:22our flash.display.sprite
02:24if you're working with Flash CS4 or up,
02:26I believe, at this stage.
02:28And if it doesn't, you just have to get used
02:29to typing in your imports or upgrading your flash editor.
02:36All right, so, and by the way,
02:37we don't talk about this often,
02:39but right now I'm working with Flash CS6,
02:40but it really doesn't matter.
02:41For the majority of the things that we're working on,
02:44it doesn't matter if you're working on Flash CS4,
02:463, 5, or 6.
02:48Just some of these, the more advanced the tool
02:50is, the faster it becomes.
02:52And the more short-hands you get.
02:55But it really isn't critical to have any specific version.
02:57All right, let's jump back in.
02:58So we know our public class is a fire.
03:00It extends sprite.
03:01And we want to have it also implement.
03:06We wanna, we're gonna say it implements itouchable
03:10because our fire is gonna be touchable,
03:12although we don't really wanna touch it.
03:14So there you go.
03:15We have our fire, which is touchable.
03:17All that's left for us to do is actually
03:19to link it to our actual fire that's on the stage.
03:23And we could do that immediately.
03:25I'm just gonna grab the full path name
03:27with the package and the class name,
03:30go back into my action script,
03:32set up, find my fire in the library,
03:35right click on it, go to my properties.
03:40And in my properties themselves,
03:42I'm gonna click on export to action script.
03:44I'm gonna set the class name to be LFire for linkage fire.
03:49And I'm gonna put in directly our base class,
03:51which is gonna be our fire base class.
03:54And there we go, we're clicking on yes, okay,
03:56we save it, and now we have ourselves a new fire
03:59which is connected to our fire class.
04:02Now, before I run it, I really wanted,
04:04I deliberately did this
04:05because I actually wanna show you what happens
04:07if you create an interface,
04:09but don't actually adhere to the rules of the interface.
04:12We haven't seen that in the last hour.
04:13So let's see what happens
04:14because we're not really implementing
04:16the touchable function, right?
04:20Our touchable function,
04:20and if we open up any of our animals,
04:22we'll see that they always have a touchable implementation.
04:26So we have your public touchable,
04:28a public touch function,
04:29which is always defined in any animal,
04:32but also in our cup.
04:34But in our fire, we don't have it.
04:35Now, what happens when we actually run our application?
04:37Because we've set that interface,
04:39we're basically breaking the rules.
04:42And because we're breaking the rules,
04:43we're gonna get an error message telling us
04:45that our interface is not implemented correctly.
04:49So basically, if we're reading interface method touch
04:51in namespace, itouchable was not implemented,
04:55and it tells us exactly
04:57that it's not finding it in our fire class.
04:59Now, I wanted also to say one thing
05:01in case you haven't done this already,
05:02although we talked about this previously,
05:05but one of our students lately
05:07kind of like sent me an issue with a file.
05:10And one of the issues
05:12were that he didn't set the flash to debugging mode.
05:15So while you're in development,
05:16make sure you're in debugging mode,
05:18although you will get this error
05:19because this is a compiling error and not a runtime error,
05:22but you definitely wanna make sure
05:24that you have your compiling setting to enable debugging.
05:29Now, to do that, you go into your FLA file,
05:31and then you go into file, publish settings, excuse me.
05:36In your publish settings,
05:38you'll see that there's a line
05:39that in the advanced line in our Swift tab
05:42that says permit debugging.
05:43Now, don't worry,
05:44different versions of flash look differently,
05:45but it works in the exact same way.
05:47So search for the permit debugging
05:49or some vernacular that's similar to that.
05:52Set that up and always set that up to be true.
05:54It's gonna make your life really easy
05:56because you're gonna get more detailed errors
05:58that tell you exactly where issues are happening
06:00instead of generic errors.
06:01Now, compiling errors as we have right now
06:05are gonna always happen.
06:06So let's fix this compiling error,
06:08and it's as easy as just adding
06:10that new public touch method.
06:12I already copied it from before,
06:13so public function touch,
06:15as soon as I add that and I run my application,
06:17we're gonna see that we're not gonna get the error anymore.
