Disabling a Component

I l @ ve RuBoard

As you saw in the last exercise, it's sometime necessary to disable a component. When you disable a component instance, that instance can no longer receive keyboard or mouse input. In this exercise you will disable the instance of the ListBox component so that it isn't clickable under the Detail Clip symbol. You will then reenable the list box when the Detail Clip movie clip is removed.

You should start this exercise with map4.fla still open .

  1. Add this code to the getDetail function in frame 1 of the Actions layer:

      animalList.setEnabled(false);  

    graphics/09fig35.gif

    Add this code to the beginning of the functionjust add a new line and start typing. When you're finished, the getDetail function should look like this:

      function getDetail(lb) {   animalList.setEnabled(false);   var idNum = lb.getSelectedItem().data;   _root.attachMovie("detailClip", "detailClip", 1);   detailClip._x = 310;   detailClip._y = 60;   detailClip.description = "<b>"+locData["common"+idNum]+"</b><br>";   detailClip.description += "<i>"+locData["latin"+idNum]+"</i><br><br>";   detailClip.description += locData["description"+idNum];   detailClip.attachMovie("closeClip", "closeClip", 1);   detailClip.closeClip._x = 230;   detailClip.closeClip._y = 4;   detailClip.closeClip.onPress = function () {   detailClip.removeMovieClip();   }   }  

    Many of the Flash UI components , including the ListBox component, can be disabled using the setEnabled method. The setEnabled method is part of the FlistBox object; the ListBox component instance is a copy of the FlistBox object. The setEnabled method has a single parameter, the value for which can be true or false. If the value is true , the component instance is enabled. If the value is false , the component instance is disabled and cannot accept mouse or keyboard interaction.

  2. Add the following ActionScript to the getDetail function:

      detailClip.onUnload = function() {   animalList.setEnabled(true);   };  

    graphics/09fig36.gif

    This code should follow the line that attaches an instance of the Detail Clip movie clip. Your getDetail function should look like this after you've completed this step:

      function getDetail(lb) {   animalList.setEnabled(false);   var idNum = lb.getSelectedItem().data;   _root.attachMovie("detailClip", "detailClip", 1);   detailClip.onUnload = function() {   animalList.setEnabled(true);   };   detailClip._x = 310;   detailClip._y = 60;   detailClip.description = "<b>"+locData["common"+idNum]+"</b><br>";   detailClip.description += "<i>"+locData["latin"+idNum]+"</i><br><br>";   detailClip.description += locData["description"+idNum];   detailClip.attachMovie("closeClip", "closeClip", 1);   detailClip.closeClip._x = 230;   detailClip.closeClip._y = 4;   detailClip.closeClip.onPress = function () {   detailClip.removeMovieClip();   }   }  

    The onUnload event of the built-in MovieClip object is triggered when the specified movie-clip instance is removed from the stage. When the removeMovieClip method is called by the instance of the Close Clip symbol inside the attached Detail Clip movie clip, the onUnload event will be triggered. This code enables the animalList ListBox instance, using the setEnabled method.

    NOTE

    Notice the semicolon (;) following the last curly brace in the code you just added. It's not required, but it's actually good syntax to add that semicolon because in essence, the code inside the curly braces is sort of like one long line of code. If you click the Auto Format button in the Actions panel, Flash will automatically add a semicolon after that curly brace .

  3. Choose Control > Test Movie.

    Select an animal from the list. When the Detail Clip movie clip is attached, you should not be able to select other animals through it. When you're finished testing, close the Test Movie window.

  4. Save the file as map5.fla in the FlashTFS folder on your hard drive.

    You're finished with the map for now. Save it as map5.fla in the FlashTFS folder on your hard drive. You'll use this file again in Lesson 12.

I l @ ve RuBoard


Macromedia Flash MX. Training from the Source
Macromedia Flash MX: Training from the Source
ISBN: 0201794829
EAN: 2147483647
Year: 2002
Pages: 115
Authors: Chrissy Rey

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net