Shaik Bilal Ahmed Mad Lab Programs

download Shaik Bilal Ahmed Mad Lab Programs

of 104

Transcript of Shaik Bilal Ahmed Mad Lab Programs

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    1/104

    MAD LAB MANUAL MCA-3rd

    YEAR 1 |P a g e

    SHAIK BILAL AHMED 10KN1F0002

    MAD Lab Programs

    Multimedia And Application Development Lab Programs List

    Submission 1

    Week 11. Assigning Actions to an Object, and a Button.2. Creating Loops.

    Week 23. Generating Ramdom Numbers4. Craeting a Function, Calling a Function.

    Week 35. Detecting the Player Version.6. Detecting the Operating System.

    Week 47. Checking the System Language.8. Detecting Display Settings

    Submission 2

    Week 59. Tinting a Movie Clips Color.

    10. Controlling a Movie Clips Color with Sliders.

    Week 611. Drawing a Circle.12. Drawing a Rectangle.

    Week 7 13. Filling a Shape with a Gradient.

    Submission 3

    Week 8 14. Scripting Masks.

    Week 9 15. Converting Angle Measurements.

    Week 10 16. Calculating the Distance Between the Two Points.

    Submission-4

    Week - 11 17. Formating Currency Amount.

    Week - 1218. Converting Between Units of Measurement.19. Determining points Along a Circle.

    Week - 1320. Sorting or Reversing an Array.21. Implementing a Custom sort.

    Week 14 22. Creating a Text Field.

    Week 1523. Making a Password Inputfield.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    2/104

    Description about MMAD Concepts:

    Multimedia has become a huge force in American culture, industry and

    education. Practically any type of information we receive can be categorized

    as multimedia, from television, to magazines, to web pages, to movies,

    multimedia is a tremendous force in both informing the American public and

    entertaining us.

    Advertising is perhaps one of the biggest industry's that use

    multimedia to send their message to the masses. Where one type of media,

    let's say radio or text can be a great way to promote an item, using

    multimedia techniques can significantly make an item being advertised better

    received by the masses and in many cases with greater results.

    Multimedia in Education has been extremely effective in teaching

    individuals a wide range of subjects. The human brain learns using many

    senses such as sight and hearing. While a lecture can be extremely

    informative, a lecture that integrates pictures or video images can help an

    individual learn and retain information much more effectively. Using

    interactive CD ROM's can be extremely effective in teaching students a wide

    variety of disciplines, most notably foreign language and music.

    As technology progresses, so will multimedia. Today, there are plenty

    of new media technologies being used to create the complete multimedia

    experience. For instance, virtual reality integrates the sense of touch with

    video and audio media to immerse an individual into a virtual world. Other

    media technologies being developed include the sense of smell that can be

    transmitted via the Internet from one individual to another. Today's video

    games include bio feedback. In this instance, a shock or vibration is given to

    the game player when he or she crashes or gets killed in the game. In

    addition as computers increase their power new ways of integrating media

    will make the multimedia experience extremely intricate and exciting.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    3/104

    AIM

    Assigning Actions to an Object, and a Button.

    PROGRAM

    Action buttons are built-in button shapes that you can add to your

    presentation and then assign an action to occur upon the click of a mouse or

    when someone mousesover the button. You can also assign actions to clip

    art, pictures, or the text in a Smart Art graphic. The idea is that when you

    deliver your presentation, you can click or mouse-over an action button to:

    Go to the next slide, the previous slide, the first slide, the last slide, the

    most recent slide viewed, a specific slide number that you specify a

    different Microsoft Office PowerPoint presentation, or a Web page.

    Run a program.

    Run amacro .

    Play a sound.

    Some examples of built-in action button shapes that you can find inthe Shapes gallery include right and left arrows and commonly understoodsymbols for going to next, previous, first, and last slides and for playingmovies or sounds, and more.

    1). On the Insert tab, in the Illustrations group, click Shapes, and then

    under Action Buttons, click the

    button that you want to add.

    2). Click a location on the slide, and then drag to draw the shape for the

    button.

    3). In the Action Settings dialog box, do one of the following:

    i). To choose the behavior of the action button when you click it in Slide

    Show view, click the Mouse

    Click tab.

    ii). To choose the behavior of the action button when you move the

    http://appendpopup%28this%2C%27ofdefmacro_1%27%29/http://appendpopup%28this%2C%27ofdefmacro_1%27%29/http://appendpopup%28this%2C%27ofdefmacro_1%27%29/http://appendpopup%28this%2C%27ofdefmacro_1%27%29/
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    4/104

    pointer over it in Slide Show view, click the Mouse Over tab.

    4). To choose the action that will take place when you click or move the

    pointer over the action button, do one of the following:

    i). To use the shape without a corresponding action, click None.

    ii). To create a hyperlink, click Hyperlink to, and then select the

    destination (for example, the next slide, the previous slide, the last

    slide, or another PowerPoint presentation) that you want the

    hyperlink action to go to.

    To link to a file created by another program, such as a Microsoft

    Office Word or Microsoft Office Excel file, in the Hyperlink to list,

    click Other File.

    iii).To run a program, click Run program, click Browse, and then locate

    the program that you want to run.

    iv). To run amacro (macro: An action or a set of actions that you can

    use to automate tasks. Macros are recorded in the Visual Basic for

    Applications programming language.), click Run macro, and then select

    the macro that you want to run.

    v). The Run macro settings are available only if your presentation

    contains a macro.

    vi). When you save the presentation, you must save it as a

    PowerPoint Macro-enabled Show.

    vii). For more information about macros, seeRun a macro.

    viii). If you want the shape that you chose as an action button toperform an action, click Object action, and then select the action that

    you want it to perform.

    NOTE The Object action settings are available only if your

    presentation contains anOLE (OLE: A program-integration

    technology that you can use to share information between

    http://appendpopup%28this%2C%27ofdefmacro_2%27%29/http://appendpopup%28this%2C%27ofdefmacro_2%27%29/http://appendpopup%28this%2C%27ofdefmacro_2%27%29/http://appendpopup%28this%2C%27ofdefmacro_2%27%29/http://office.microsoft.com/search/redir.aspx?AssetID=HA101181991033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101181991033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101181991033&CTT=5&Origin=HA100243511033http://appendpopup%28this%2C%27idh_ofdefole_3%27%29/http://appendpopup%28this%2C%27idh_ofdefole_3%27%29/http://appendpopup%28this%2C%27idh_ofdefole_3%27%29/http://appendpopup%28this%2C%27idh_ofdefole_3%27%29/http://appendpopup%28this%2C%27idh_ofdefole_3%27%29/http://office.microsoft.com/search/redir.aspx?AssetID=HA101181991033&CTT=5&Origin=HA100243511033http://appendpopup%28this%2C%27ofdefmacro_2%27%29/http://appendpopup%28this%2C%27ofdefmacro_2%27%29/http://appendpopup%28this%2C%27ofdefmacro_2%27%29/
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    5/104

    programs. All Office programs support OLE, so you can share

    information through linked and embedded objects.) object. For more

    information about OLE objects seeCreate, change, or delete an OLE

    object

    ix). To play a sound, select the Play sound check box, and then selectthe sound that you want to play.

    5). Click OK.

    1). On the Insert tab, in the Illustrations group, do one of the

    following:

    i). Click Picture, and then in the Insert Picture dialog box, locate

    the picture that you want to add, and then click Insert.

    ii). Click Clip Art, and then in the Clip Art pane, locate and thenclick the picture that you want to add.

    NOTE You can assign an action to the text inside the shapes of a

    SmartArt graphic, but not to the SmartArt shapes themselves. For

    more information about inserting SmartArt graphics, seeCreate a

    SmartArt graphic.

    1). Click the picture or clip art that you added, and then on the Insert

    tab, in the Links group, click Action.

    1). In the Action Settings dialog box, do one of the following:

    i). To choose the behavior of the picture or clip art when you click it

    in Slide Show view, click the Mouse Click tab.

    ii). To choose the behavior of the picture or clip art when you move

    the pointer over it in Slide Show view, click the Mouse Over tab.

    1). To choose the action that will take place when you click or move the

    pointer over the picture or clip art, do one of the following:

    i). To use the shape without a corresponding action, click None.

    ii). To create a hyperlink, click Hyperlink to, and then select the

    destination (for example, the next slide, the previous slide, the last

    http://office.microsoft.com/search/redir.aspx?AssetID=HA101991921033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101991921033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101991921033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA012058671033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA012058671033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA012058671033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA012058671033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA012058671033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA012058671033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101991921033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101991921033&CTT=5&Origin=HA100243511033
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    6/104

    slide, or another PowerPoint presentation) that you want the hyperlink

    action to go to.

    NOTE To link to a file created by another program, such as a

    Microsoft Office Word or Microsoft Office Excel file, in the Hyperlink

    to list, click Other File.

    iii). To run a program, click Run program, click Browse, and then

    locate the program that you want to run.

    iv). To run amacro (macro: An action or a set of actions that you

    can use to automate tasks. Macros are recorded in the Visual Basic for

    Applications programming language.), click Run macro, and then

    select the macro that you want to run.

    NOTES

    v). The Run macro settings are available only if your

    presentation contains a macro.

    vi). When you save the presentation, you must save it as a

    PowerPoint Macro-enabled Show.

    viii). For more information about macros, seeRun a macro.

    ix). If you want the picture or clip art to perform an action otherthan what is listed, click Object action, and then select the action that

    you want it to perform.

    NOTE The Object action settings are available only if your

    presentation contains anOLE (OLE: A program-integration

    technology that you can use to share information between

    programs. All Office programs support OLE, so you can share

    information through linked and embedded objects.) object. For more

    information about OLE objects seeCreate, change, or delete an OLE

    object

    x). To play a sound, select the Play sound check box, and then

    select the sound that you want to play.

    http://appendpopup%28this%2C%27ofdefmacro_4%27%29/http://appendpopup%28this%2C%27ofdefmacro_4%27%29/http://appendpopup%28this%2C%27ofdefmacro_4%27%29/http://appendpopup%28this%2C%27ofdefmacro_4%27%29/http://office.microsoft.com/search/redir.aspx?AssetID=HA101181991033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101181991033&CTT=5&Origin=HA100243511033http://appendpopup%28this%2C%27idh_ofdefole_5%27%29/http://appendpopup%28this%2C%27idh_ofdefole_5%27%29/http://appendpopup%28this%2C%27idh_ofdefole_5%27%29/http://appendpopup%28this%2C%27idh_ofdefole_5%27%29/http://appendpopup%28this%2C%27idh_ofdefole_5%27%29/http://office.microsoft.com/search/redir.aspx?AssetID=HA101991921033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101991921033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101991921033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101991921033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101991921033&CTT=5&Origin=HA100243511033http://office.microsoft.com/search/redir.aspx?AssetID=HA101991921033&CTT=5&Origin=HA100243511033http://appendpopup%28this%2C%27idh_ofdefole_5%27%29/http://appendpopup%28this%2C%27idh_ofdefole_5%27%29/http://appendpopup%28this%2C%27idh_ofdefole_5%27%29/http://appendpopup%28this%2C%27idh_ofdefole_5%27%29/http://office.microsoft.com/search/redir.aspx?AssetID=HA101181991033&CTT=5&Origin=HA100243511033http://appendpopup%28this%2C%27ofdefmacro_4%27%29/http://appendpopup%28this%2C%27ofdefmacro_4%27%29/http://appendpopup%28this%2C%27ofdefmacro_4%27%29/
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    7/104

    AIM

    Creating Loops.

    PROGRAM

    Audio that loops seamlessly creates a perfect soundtrack for many

    Flash animations and video spots.

    1. In the Tasks panel, click Create Loop.

    In the transport controls, Soundbooth automatically enables the

    Loop Playback option .

    2. Press the spacebar to start playback.

    3. In the Editor panel, select a time range for the loop.

    4. In the Tasks panel, fine-tune the loops in point, out point, and

    duration.

    5. Select from the following options:

    Lock Duration

    Restricts the loop to the currently specified duration. If you need a

    loop of precise length, select this option, and adjust the in point and

    out point as needed.

    Auto-Smooth Loop Point

    Cross-fades audio from the out point to the in point, creating a

    smoother transition.

    Play Entire Loop/Play Transition Only

    Previews either the entire loop or only the transition from out point

    to in point.

    6. Click Save Loop As to save the loop to a new file.

    Select time ranges

    1. In the toolbar, select the Time Selection tool .

    2. In the Editor panel, drag to select a range.

    3. (Optional) Do any of the following:

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    8/104

    i). To extend or shorten a selection, Shift-click the end of the

    selection that you want to modify, and drag to extend or shorten it. Or,

    drag the left or right edge of the selection in the timeline ruler.

    ii). To move the selection without changing its length, drag the

    middle of the selection in the timeline ruler.

    Save entire files or selected ranges

    Use the File > Save command to either save newly created files or quickly

    resave existing files and retain their settings. Use the File > Save As

    commands to save selections or change settings such as file format, sample

    rate, and bit depth.

    1. Choose one of the following:

    i). File > Save. (Ifyoure resaving, you can skip all steps below.)

    ii). File > Save As.

    iii). File > Save Selection As.

    2. Specify a file location, name, and format. Then click Save.

    3. Set format-specific options. For more information, see one of the

    following: mp3 options.

    AIF, AVI, MOV, and WAV options.

    Options for additional video formats.

    4. Click OK.

    http://livedocs.adobe.com/en_US/Soundbooth/1.0/WS1D882DD5-C0CB-483f-AFA4-ECFDEF1650B2.htmlhttp://livedocs.adobe.com/en_US/Soundbooth/1.0/WS34FCC06A-F0FA-40fc-980D-946863BE87EA.htmlhttp://livedocs.adobe.com/en_US/Soundbooth/1.0/WS3DA5F916-EDFE-460a-BCF0-72FA40CCFA65.htmlhttp://livedocs.adobe.com/en_US/Soundbooth/1.0/WS3DA5F916-EDFE-460a-BCF0-72FA40CCFA65.htmlhttp://livedocs.adobe.com/en_US/Soundbooth/1.0/WS34FCC06A-F0FA-40fc-980D-946863BE87EA.htmlhttp://livedocs.adobe.com/en_US/Soundbooth/1.0/WS1D882DD5-C0CB-483f-AFA4-ECFDEF1650B2.html
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    9/104

    AIM

    Generating Ramdom Numbers

    PROGRAM

    Generating Random Numbers

    When you need to incorporate random elements into your Flash movie,either for a design effect or for game play, you can use the Math class'sMath.random() method. The Math.random() method generates randomnumbers between 0 and 1 (including 0 but not including 1) with up to 15decimal places in between. Typical return values are

    0.2423435445982730.0436287384938290.7567833408654

    The Math object in ActionScript contains a number of methods thatperform mathematical operations. Among these is random(), whichgenerates an apparently random number between 0 and 1. To generate a

    random-number value and assign it to a variable, use a statement like this:

    someVariable = Math.random();

    Note that the "M" in Math must always be capitalized. The names ofpredefined objects are always given this way.

    Technically speaking the output of Math.random() is only pseudo-

    random, because the technique used to generate its values will display adetectable pattern if it is repeated enough times. But unless you have thepatience to scrutinize hundreds of thousands of repetitions, you probablywon't notice.

    Below are five movies showing Math.random() in action. In each

    movie a script displays randomly generated numbers or words.

    The script is installed within a Movie Clip called scripts, which appearsin the upper right corner of the movie window. This element may look like abutton but it's just a convenient place to park the scripts. In a real project

    we'd probably make this Movie Clip invisible.

    Some scripters prefer to place general scripts in the first frame of a

    layer devoted exclusively to scripting. This is an even simpler solution.

    Also on the right side you'll find a button marked Repeat. This buttoninvokes a function defined within the Scripts Movie Clip. This allows you tore-run the demonstration function as many times as you like.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    10/104

    The first demonstration movie below shows the results ofMath.random() invoked four times.

    By themselves, long decimal numbers between 0 and 1 are not muchhelp in controlling Flash movies. To select from among a range of elements,you'll probably want to match the output ofMath.random() against a seriesof tests, as in this example:

    The first demonstration movie below shows the results of

    Math.random() invoked four times.

    By themselves, long decimal numbers between 0 and 1 are not muchhelp in controlling Flash movies. To select from among a range of elements,you'll probably want to match the output ofMath.random() against a seriesof tests, as in this example:

    if(randyItem == 0) loadMovie("firstCourse.swf",0);if(randyItem == 1) loadMovie("secondCourse.swf",0);if(randyItem == 2) loadMovie("thirdCourse.swf", 0);

    if(randyItem == 3) loadMovie("fourthCourse.swf", 0);if(randyItem == 4) loadMovie("fifthCourse.swf", 0);

    These five lines allow you to choose a new movie at random and loadit over the present movie.

    As you can see, the iftests here assume we're dealing with integers.Two steps are required to get from the raw output of Math.random() touseful integer values.

    First, multiply the output ofMath.random() by the number of items

    from which you wish to choose. In the example above we'd multiple by 5:

    someVariable = Math.random()*5;

    Here's what this change does to our initial example:

    As you can see, when you multiply an integer like 5 by a messydecimal number like 0.427009978920274, the result is itself a messy decimal

    (2.13504989460137, to be exact).

    We need a simple integer. To clean up the results we apply another

    method of the Math object called floor(). This method rounds the decimaldown to the nearest integer. In the case above, it yields 2. The statement

    looks like this:

    someVariable = Math.floor(Math.random()*5);

    Be careful with those embedded parentheses; you have to get them just

    right.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    11/104

    Here are four more iterations ofMath.random(), this time multiplied by 5and rounded down with Math.floor():

    If you study the output above, you'll see that the random values may include0 but never include 5. That's because we're always rounding down. If wewanted to include 5 and exclude 0, we'd use the Math.ceil() functioninstead ofMath.floor().

    Which function you choose depends on what you want to do with the randomvalue. In many cases you may want to do something slightly different fromthe example discussed earlier (a series ofiftests). You may want to extracta randomly-chosen value from a specially constructed object called an Array.At heart, Arrays are simply ordered lists, though their numbering systems

    differ from everyday practice in one respect: they always start at 0.

    Arrays are numbered from 0 to one less than their total length--from 0 to 14for a fifteen-element array. Thus the numbers generated by a randomfunction rounded down with Math.floor() will always correspond to indices

    of the array. If we write an array containing fifteen words, we can now use

    Math.floor(Math.random()*15)) to generate a random word list:

    Constraining Random Values

    If you re-run the example above a few times, you'll notice that it oftencontains duplicate items, and that these duplicates may occur one afteranother. This happens because we're choosing from a relatively small range

    of options, and because nothing prevents the script from generating thesame random integer twice in succession. (Technically speaking, the problemlies with the Math.floor() operation, which takes nearly unique decimals and

    rounds down to a much smaller range of integers.)

    You can minimize repetition by keeping track of the random function's pastperformance and screening out previously-used values. Here's an example ofrandom selection constrained to produce five unique selections from a list of

    fifteen words:

    To explain this technique as clearly as possible, we'll first discuss a simplerform of constraint than what you see above--constraint against only a single

    repetition. Then we'll show how to scale the procedure up.

    Here's how to achieve a simple, first-order constraint. First, we initialize a

    pair of variables to the same value:

    var randy = 0;var randyOld = 0;

    In ActionScript as in JavaScript, it's possible to place certain statementsinside control structures such as loops and functions so that they can berepeated on command. The statements above must be placed outside anysuch structures and be executed only once, when the movie loads. In the

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    12/104

    example above they are placed within an onClipEvent(load) handlerattached to the Scripts Movie Clip. You'll see why this placement is

    important in just a moment.

    The first variable, randy, holds the current random value. The othervariable, randyOld, is used to store the random value generated on theprevious run of the function.

    Needless to say, when the movie is loaded there has been no previous run,so we have to supply initial values. It's essential that both variables be

    assigned the same value. Again, you'll see why in just a bit.

    Next we make a change to the statement that generates the random number

    randy. In the unconstrained version of the function, that statement is:

    randy = Math.floor(Math.random()*contentArray.length);

    In the constrained case, however, we place this statement within a specialconstruction called a while loop:

    while(randy == randyOld){randy = Math.floor(Math.random()*contentArray.length);

    }

    A while loop executes so long as its conditional clause evaluates to true. Inthis case, so long as the random number we generate is the same as therandom number we previously generated, we generate a new randomnumber. In other words we keep trying numbers until we hit one that is notthe same as the one that came up previously.

    This is why both randy and randyOld must have the same value on the first

    run of the function: we only get a random value if the two variables are

    identical.

    One more refinement makes the constraint complete. Outside the while loopwe add this statement:

    randyOld = randy;

    This statement records the current random number and stores it in the

    variable that will be used for comparison on the next run of the function. Thisline lets the function remember its previous behavior each time through.

    Extensions of Constraint

    Using the logic explained above, you may constrain a random numbergenerator against several orders of repetition, so that it is guaranteed toproduce non-repeating values for three, four, five, or more successiveiterations. The crudest way to do this is simply to create more storage

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    13/104

    variables (randyOlder and randyOldest, for instance), write a compoundtest condition for the while loop, and push every new random value back

    through the record variables as we go.

    If you look at the scripts attached to the Scripts Movie Clip in thedemonstration movie above, you'll find five constraint variables. That's not avery elegant solution, but you may find it easier to take in at a glance than

    some of the alternatives.

    After the fifth level of constraint, brute-force methods may become toocumbersome for most people's tastes. It's awkward to write a test conditionwith six or seven parallel cases. At this point you might want to use an arrayinstead of separate variables to store the record values. This means writing

    code to scan that array. Alternatively you could write previous random valuesto a string, moving each value one place back as it ages out; but again,you'd have to write code to look for values in that string.

    Practically speaking, if the range of content choices is large enough, there

    may be no reason to constrain the randomizer against more than two or

    three repetitions.

    Better Solutions

    The method we've just discussed has important flaws--executed on a veryslow system it can behave sluggishly if the system randomly selects thesame number many times in a row. Real programmers have better ways of

    constraining random number generation; unfortunately, these methods are

    hard to explain to people (like me) who are mathematically challenged.

    The scheme described above should work fine for Flash movies for two

    reasons: first, Flash is very well integrated with PC operating systems so itmakes excellent use of processing resources; second, most PCs today have

    plenty of computing power to spare for tasks like multimedia.

    So unless you have a deep dislike for sloppy solutions, you may use this

    method with random abandon.

    The Deprecated random() Function

    If you used ActionScript in its earlier iterations (Flash 3) you may haveencountered a simpler random() function. Given an argument N, this

    function would return an integer between 0 and N-1, inclusive. It wasn'tnecessary to use Math.floor() or Math.ceil().

    Macromedia has officially deprecated the old random function, partly (weguess) because it is not consistent with the way people learn to code in Javaand JavaScript, and partly because floor and ceiling functions allow greater

    control.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    14/104

    Though it's simpler to write, do not include the old random function in yourcode. You should never use deprecated commands when you can avoidthem. Though Macromedia is very generous about legacy code, once aninstruction is deprecated it need no longer be supported. Some future versionof Flash will refuse to recognize the old random function.

    Source Files

    The five demonstration movies that appear on this page are calledrandom1.fla, random2.fla, random3.fla, random4.fla, andrandom5.fla. They're available on Crow within MMShare/randoms. Ineach movie the scripts are attached to the Scripts Movie Clip.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    15/104

    AIM

    Craeting a Function, Calling a Function.

    PROGRAM

    The following is a step-by-step description of the process that

    happens when you create an event listener. In this case, it's anexample of creating a listener function that is called when an object

    named myButton is clicked.

    The actual code written by the programmer is as follows:

    function eventResponse(event:MouseEvent):void{

    // Actions performed in response to the event go here.}

    myButton.addEventListener(MouseEvent.CLICK, eventResponse);

    Here is how this code would actually work when it's runningin Flash Player:

    1. When the SWF file loads, Flash Player makes note of the fact thatthere's a function named eventResponse().

    2. Flash Player then runs the code (specifically, the lines of code thataren't in a function). In this case that's only one line of code: calling the

    addEventListener() method on the event source object (namedmyButton) and passing the eventResponse function as a parameter.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    16/104

    a. Internally, myButton has a list of functions that are listening toeach of its events, so when its addEventListener() method iscalled, myButton stores the eventResponse() function in its list of

    event listeners.

    3. At some point, the user clicks the myButton object, triggering its clickevent (identified as MouseEvent.CLICK in the code).

    At that point, the following occurs:

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    17/104

    a. Flash Player creates an object, an instance of the class associatedwith the event in question (MouseEvent in this example). Formany events this will be an instance of the Event class; for mouseevents it will be a MouseEvent instance; and for other events itwill be an instance of the class that's associated with that event.This object that's created is known as the event object, and it

    contains specific information about the event that happened: whattype of event it is, where it happened, and other event-specificinformation if applicable.

    b. Flash Player then looks at the list of event listeners stored bymyButton. It goes through these functions one by one, callingeach function and passing the event object to the function as aparameter. Since the eventResponse() function is one ofmyButton's listeners, as part of this process Flash Player calls the

    eventResponse() function.

    c. When the eventResponse() function is called, the code in thatfunction runs, so your specified actions are carried out.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    18/104

    RelatedTopics

    Popup

    Popup

    Flash CS3

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    19/104

    AIM

    Detecting the Player Version.

    PROGRAM

    Detecting the Flash Player

    What good is an awesome Flash experience if no one can see your Flashmovies? Because most Flash content is viewed with a Web browser, it'sextremely important to make sure that your HTML pages check for the existenceof the Flash Player plug-in before you start pushing Flash content to the browser.There are a variety of ways to check for the Flash Player, and this sectionprovides an overview of the available methods.

    New

    Feature

    As we mentioned in the previous chapter, Flash 8 includes an

    updated Flash Player detection feature within the Publish Settings.You learn how to create a set of detection pages with this newfeature later in this chapter.

    Plug-In versus ActiveX: Forcing Content without a Check

    The Flash Player is available for Web browsers in two forms: the Flash Playerplug-in (as a Netscape-compatible, or Mozilla-compatible, plug-in) and the FlashPlayer ActiveX control (for use only with Microsoft Internet Explorer on Windows

    98/ME/2000/XP).

    If you directly insert a Flash movie into a Web page with the tag (forNetscape browsers), one of two scenarios will happen:

    The browser has the Flash Player plug-in and will load the Flash movie.The browser does not have the Flash Player plug-in and displays a brokenplug-in icon.

    If the second scenario occurs and the pluginspage attribute of the tagis defined, the user can click the broken plug-in icon and go to the Macromedia

    site to download the Flash Player plug-in. If the pluginspage attribute is notspecified, clicking the broken plug-in icon will take you to a generic Netscapeplug-in page.

    If you insert a Flash movie into an HTML document with the tag (forInternet Explorer on Windows only), one of two scenarios will happen:

    The browser has the Flash Player ActiveX control and will load the Flashmovie.

    http://www.freeopenbook.com/flash8-bible/BBL0192.html#1904http://www.freeopenbook.com/flash8-bible/BBL0192.html#1904
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    20/104

    The browser does not have the Flash Player ActiveX control and willautodownload and install the ActiveX control file from the Macromediasite.

    Note Newer versions of Windows XP (that is, with Service Pack 2 or SP2installed) will likely get an additional warning represented as a strip acrossthe top of the Web page attempting to initiate the installation of a new

    ActiveX control. The user must also click this strip and accept the downloadof the ActiveX control.

    The ActiveX control will autodownload and install only if the classid andcodebase attributes of the Flash movie's tag are correctly specified.Depending on the user's security settings, the user needs to grant permission toa Security Warning dialog box to commence the download and install process.

    Although using the and tags by themselves is by far thesimplest method for integrating Flash content into a Web page, it's not the mostuser-friendly method of ensuring that the majority of your Web visitors can view

    the Flash content. Flash 8 uses a new JavaScript detection mechanism, updatingthe Flash sniffer approach used in Flash MX 2004.

    Note Since Flash Player 4 was released, many seasoned Flash developers haveused small Flash movies known as sniffers to detect the presence of theFlash Player in a user's Web browser. Sniffers are virtually hidden from thevisitor to a Web site, and they direct an entry HTML page to a new location(using a getURL() action) where the real Flash content (or site) exists. If thePlayer is not installed, the sniffer movie won't be able to play and direct theHTML page to a new location. If this happens, a special tag in the of the HTML document directs the browser location to a screen that

    informs the visitor to down load the plug-in or ActiveX control.

    Detecting the Flash Player with Flash 8

    In Flash 8, Macromedia has made the process of using a sniffer methodologyincredibly simple. In the following steps, you learn how to use the new DetectFlash Version feature to properly direct a user to Flash Player 6 r65 content.

    Note You can check for Flash Player 4 or higher with the Detect Flash Versionfeature. For demonstration purposes, we chose Flash Player 6 r65 becauseFlash MX 2004 introduced a new optimization feature for .swf files

    generated for this version (or higher) of Flash Player 6.Caution If you use the Detect Flash Version in Flash MX 2004, be sure to reviewthis section. The feature no longer uses three HTML pages for thedetection process. Everything from the detection to the content display tothe alternate content display occurs on one HTML page.

    1. Create a new Flash document by choosing File New. In the NewDocument dialog box, choose Flash Document and click OK. Alternatively,open an existing .fla file that you have created and skip to Step 4.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    21/104

    2. Save the new Flash document as detection_test.fla.3. Add some placeholder text to the stage using the Text tool. As this

    example is checking for Flash Player 6 r65, you can type This is FlashPlayer 6 r65 content.

    4. Choose File Publish Settings. By default, both the Flash and HTMLformats are selected in the Formats tab of the Publish Settings dialog box.The filenames for these formats should reflect the current .fla filename,

    such as detection_test.swf and detection_test.html, respectively.5. To keep the new version settings in a separate profile, click the CreateNew Profile (+) button at the top of the Publish Settings dialog box. Namethe profile FP6 r65 Detection, as shown in Figure 22-3. Click OK to closethe dialog box, but leave the Publish Settings dialog box open.

    6. Click the Flash tab. In the Version menu, choose Flash Player 6. In theActionScript version menu, choose ActionScript 1.0. Select the Optimizefor Flash Player 6 r65 check box. Refer to Figure 22-4 for a review ofthese settings.

    7. Click the HTML tab of the Publish Settings dialog box. Select the DetectFlash Version check box. The two editable text fields to the right of the

    Version label should now be enabled. The major version of the FlashPlayer is fixed to the Player version you chose in the Flash tab. The first ofthe two editable fields represents a Minor Revision value; to date,Macromedia hasn't released any minor revisions of the Flash Player, butthis feature is enabled just in case Macromedia does release any minorrevision during the life cycle of the Flash 8 authoring tool. The second fieldrepresents the Incremental Revision value. Since Flash Player 4,Macromedia has released several incremental revisions of the FlashPlayer for each player cycle.

    Web

    Resource

    To get a sense of how many incremental revisions of Flash

    Player 7 were released, see the "Flash Player ReleaseNotes" category at www.flashsupport.com/links. Caution In Flash MX 2004, Macromedia referred to these two editable

    values as Major Revision and Minor Revision. With a littlerevisionist history in Flash 8, Macromedia now refers to MajorRevision as Minor Revision and Minor Revision as IncrementalRevision.

    9. Type 65 in the second field, as shown in Figure 22-5. If you wanted tocheck for a different incremental version of Flash Player 6, you could enterthat value instead. Click OK to close the dialog box, and go back to theHTML tab of the Publish Settings dialog box.

    10. In the Publish Settings dialog box, click the Publish button. You may seean alert box, as shown in Figure 22-6, letting you know that the Flashmovie file (.swf) you are about to publish is only compatible with FlashPlayer 6 r65 or higher. Click OK in this alert box. Flash 8 generates all ofthe necessary JavaScript within the published HTML document to properlydetect the Flash Player version. Click OK to close the Publish Settingsdialog box.

    http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig03#ch22fig03http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig04#ch22fig04http://www.flashsupport.com/linkshttp://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig05#ch22fig05http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig06#ch22fig06http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig06#ch22fig06http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig05#ch22fig05http://www.flashsupport.com/linkshttp://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig04#ch22fig04http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig03#ch22fig03
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    22/104

    11. On your desktop, navigate to the folder where you saved your original .flafile. If you created the sample document in Step 1, you want to find thelocation of detection_test.fla. In this location, you will see the HTML fileused for the detection process, the Flash content, and the alternatecontent.

    12. In your own Web browser, load the detection_test.html page. If yourbrowser has Flash Player 6 r65 or higher, the browser should display your

    detection_test.swf movie. This process works because thedetection_test.html page uses JavaScript (or VBScript on Internet Explorerfor Windows) to check the installed Flash Player version, if one exists. Ifyou open the HTML document in a text editor such as MacromediaDreamweaver, you'll see that lines 1015 declare the version numbersyou entered in the HTML tab of the Publish Settings. The JavaScript codecompares these values to the version of the Flash Player that loaded themovie. If the Flash Player matches (or exceeds) the version requirements,the Flash content tags ( and ) are written to the HTMLpage with JavaScript. Otherwise, the alternate content specified on line147 in the JavaScript code is loaded into the browser window.

    Note Macromedia provides generic alternate content that you shouldreplace with your own preferred HTML tags indicating what you wantto the user to do if the version of the Flash Player required is notinstalled.

    13. To accurately test your pages over an Internet connection, upload all ofthe files (except the .fla file) to your Web server and load thedetection_test.html document from the Web server URL to redo the test.

    Figure 22-3: The Create New Profile dialog box, showing the new profile name

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    23/104

    Figure 22-4: The Flash Player 6 r65 settings in the Flash tab

    Figure 22-5: The Publish Settings dialog box

    Figure 22-6: The Optimize for Flash Player 6 r65 alert boxOn the CD-ROM

    You can find all of these files created for this detection examplein the ch22/flash8_detection folder of this book's CD-ROM. TheJavaScript in the detection_test_f8b.html version of the documentcontains additional alternate content that is specified in analternate.js file, also included on the CD-ROM. If you'd like to findthe latest "Get Flash Player" graphics to use in your Web pages,

    http://www.freeopenbook.com/flash8-bible/images/fig794_01_0.jpghttp://www.freeopenbook.com/flash8-bible/images/fig793_01_0.jpg
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    24/104

    go to www.macromedia.com/macromedia/style_guide/buttons.

    If you want to test the detection mechanism with an older version of the FlashPlayer, we recommend that you use an older Flash Player installer with Netscapeor a Mozilla-compatible browser. The process of uninstalling an ActiveX controlused by Internet Explorer is much more difficult to do.

    WebResource

    You can find just about every past version of the Flash Player atwww.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14266 for testing purposes. As mentioned previously, we recommend thatyou install the older versions with a Netscape or Mozilla-compatiblebrowser. If you are using Mac OS X, the first Flash Player released forMac OS X was version 5.

    You can set up your Netscape or Mozilla-compatible browser's plug-ins folder toaccommodate multiple versions of the Flash Player plug-in. When you installedFlash 8, the first release of Flash Player 8 should have automatically beeninstalled to your Netscape (or Mozilla) browser's Plugins (or plugins) folder. The

    plug-in file, named NPSWF32.dll, can be moved outside of the Plugins folder,into a new parent folder that you create. For the following example, we'll useMozilla FireFox as our test browser.

    WebResource

    Mozilla FireFox is a free Web browser that you can download atwww.mozilla.org/products/firefox/. FireFox has quickly become thepreferred cross-platform browser of many Web developers.

    We prefer to create a _Flash Players folder in theC:\ProgramFiles\MozillaFireFox folder, and put each Flash Player version plug-infile into its own folder, as shown in Figure 22-7.

    Figure 22-7: A sample Flash Players folder structure for use with Mozilla FireFoxon WindowsCaution Regardless of the Flash Player version you install, all Flash Player plug-

    in files for Netscape or Mozilla-compatible browsers have the same

    http://www.macromedia.com/macromedia/style_guide/buttonshttp://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14266http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14266http://www.mozilla.org/products/firefox/http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig07#ch22fig07http://www.freeopenbook.com/flash8-bible/images/fig796_01_0.jpghttp://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig07#ch22fig07http://www.mozilla.org/products/firefox/http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14266http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14266http://www.macromedia.com/macromedia/style_guide/buttons
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    25/104

    name on Windows: NPSWF32.dll. For this reason, you must isolatemultiple installations of the Flash Player into their own folder.

    You can do the same procedure on Mac OS X, where all browsers share thesame plug-in folders. That's right! Mozilla, FireFox, Internet Explorer, and AppleSafari all refer to the same plug-ins folder. On your boot disk, such as MacintoshHD, browse to the Library\Internet Plug-Ins\ folder. In this location, you will find

    the Shockwave Flash NP-PPC plug-in file. As Figure 22-8 shows, you can createa Library\Internet Plug-Ins (DISABLED) folder to store other versions of this plug-in file.

    Figure 22-8: A sample Flash Players folder structure for use with Mozilla FireFoxor Apple Safari on Mac OS XCaution On Mac OS X, you may need to re-create the same plug-in structure

    with the Users\[Your User Name]\Library\Internet Plug-Ins\ folder. Or,you may just want to remove any Flash Player plug-in files within thisfolder. Mac OS X should then default to the main Library\Internet Plug-Ins\ folder.

    This process takes some time, as you have to download and run each installerfrom the URL we mentioned in the earlier Web Resource note, and move theNPSWF32.dll file from the Plugins folder to its own folder in the Flash Playersfolder. When you're done, however, you'll have an efficient system for checkingyour content against older versions of the Flash Player. Simply move the currentNPSWF32.dll file into its appropriate _Flash Players folder, and move the desiredtest version from its Flash Players folder into the Plugins folder.

    Building Your Own Flash Sniffer Movie

    While the Macromedia Flash 8 detection features work wonderfully, you maywant to know how to build your own custom Flash detection sniffer. In thissection, you learn how to build a Flash movie that uses client-side ActionScript to

    http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig08#ch22fig08http://www.freeopenbook.com/flash8-bible/images/fig797_01_0.jpghttp://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22fig08#ch22fig08
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    26/104

    direct the browser window to the appropriate content. This sniffer directs eachversion of the Flash Player to its own unique HTML page. Meaning, Flash Player3 (or earlier) is directed to a flash3.html page, Flash Player 4 is directed to aflash4.html page, Flash Player 5 jumps to a flash5.html page, and so on.

    Making the Sniffer Movie

    The sniffer movie is a small Flash movie that has the same background color asthe HTML document. You do not need any artwork or symbols in this movie.

    1. Open Flash 8, and in a new Flash document file (.fla), rename Layer 1 toactions.

    2. Add a keyframe on frame 2 of the actions layer. With this keyframeselected, open the Actions panel (F9 or Option+F9 on Mac).

    3. In the Actions panel, add some ActionScript that checks for Flash Player 3(or earlier). If Flash Player 3 is detected, then the movie will stop here andlaunch a URL for Flash 3 movies. If a later version of the player isdetected, a separate keyframe labeled checkPlayer is called. You can

    direct each version of the Player to a unique URL. The basic principle ofthis ActionScript is to use Flash version-specific actions to determinewhich Player is displaying the movie. Refer to Listing 22-1.

    Listing 22-1: The Detection Script on Frame 2 of the actions Layer

    // create a Flash variable, whose value is equal to the// $version environment variable in Flash Player 4, 5,// or 6. This action line will not be read by Flash// Player 3(or earlier).

    player = eval("$version");

    // The $version value will be in the format://// abc 1,2,3,4//// where abc is the operating system (e.g. WIN, MAC)// and 1 and 2 are the major version designations// (e.g. 4.0, 5.0, etc.) and 3 and 4 are the minor and// sub-minor version designations (e.g. r20, r27, etc.)//// By default, Flash MX 2004 ships with a Player version equal// to WIN 7,0,0,0 or MAC 7,0,0,0. However, the Flash// Player is available on other platforms like UNIX and

    // POCKETPC as well.//// We just need the major version designation at// placeholder 1. Using a while loop and substring(), we// can extract this number, searching for the space (" ")// between the platform text and the version numbers. The// major version starts just after the space (" "). The// Flash Player 3 will disregard this section of code.

    playerLength = length(player);

    http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22list01#ch22list01http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22list01#ch22list01
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    27/104

    i=1;

    while (i

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    28/104

    } else if (Number(majorVersion) == 7) {// Flash Player 7 or higher will execute this code.getURL("flash7.html");

    } else if (Number(majorVersion) >= 8) {// Flash Player 8 or higher will execute this code.getURL("flash8.html");

    }

    6. Change the size of the movie frame to 18 px 18 px, in the DocumentProperties dialog box (Modify Document). Change the background colorof the movie to match the background color of the HTML document. ClickOK.

    NewFeature

    In Flash 8, you can now specify movie dimensions as smallas 1 px 1 px. While 18 px 18 px is small enough toremain unnoticeable on a Web page, you can opt to makeyour Flash movie even smaller.

    7. Save the Flash movie as sniffer.fla.8. Open the Publish Settings dialog box (File Publish Settings). Make sure

    the Flash and HTML options are selected in the Formats tab. Rename theHTML file sniffer_start.html.

    9. In the Flash tab, select Flash Player 4 in the Version drop-down menu.

    Note You are using the Flash Player 4 format because Flash Player 3ignores all Flash 4 or higher actions, and Flash Player 4 or higherrecognizes the formatting of the variable and ActionScript structures.Flash Player 5 .swf files restructure variables and ActionScript (even

    Flash 4-compatible code) in a manner that doesn't work consistentlyin Flash Player 4.

    10. In the HTML tab, select the Flash Only template. Click the Publish buttonlocated at the bottom of the Publish Settings dialog box.

    11. When the files have been published, click OK to close the Publish Settingsdialog box. Save your document again.

    You now have sniffer_start.html and sniffer.swf files in the same folder as yoursniffer.fla file. In the next section, you add some additional HTML tags to thesniffer. html document.

    Integrating the Sniffer Movie into an HTML Document

    After you have made the sniffer.swf and the sniffer.html files, you can modify theHTML document to guide the browser to a unique URL where plug-in informationand a down load screen are shown. Remember that the indicates a continuationof the same line of code. Do not insert this character into your HTML document.

    http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22lev3sec2#ch22lev3sec2http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22lev3sec2#ch22lev3sec2
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    29/104

    1. Open the sniffer_start.html file in your preferred HTML document editor.Macromedia Dreamweaver, Notepad (Windows), TextEdit (Mac), orBBEdit (Mac) will do just fine.

    2. Somewhere between the tags, insert the following HTML tag as one line of code:

    3.

    This tag has two attributes, http-equiv and content. The http-equivattribute instructs the hosting Web server to add the value of http-equiv asa discrete name in the MIME header of the HTML document. The value ofthe content attribute becomes the value of the MIME entry. Here, the Webbrowser will interpret the META tag as

    Refresh: 3; URL=download.html

    in the MIME header. This name/value pair tells the browser to reload thebrowser window in three seconds with the file download.html. After testing,

    you may decide to increase the time the browser waits before reloading anew URL. On slower connections (or during peak Internet hours), you mayfind that three seconds is not long enough for the initial HTML and Flashmovie to load into the browser.

    Caution Some older browsers may require an absolute URL in the contentattribute. This means that you may need to insert a full path toyour HTML document, such ashttp://www.yourserver.com/download.html, as the URL in thecontent attribute.

    5. You may want to create some text on this HTML document that indicatesits purpose. If the user does not have the plug-in installed, he or she willbe staring at a blank white page until the refresh is activated. For thepurposes of this example, create an HTML table that centers the text"Checking for Flash Player " on the page.

    6. Save the HTML file as sniffer.html. If you want this to be the default pagefor your Web site, you may need to rename this file to index.html,idex.htm, index.cfm, or to whatever filename your Web server isconfigured to use as a default page. At this point, you need to create adownload.html file. You also need to create flash3.html, flash4.html,flash5.html, flash6.html, and flash7.html files for the getURL() actions in

    the sniffer.swf movie.

    On the CD-ROM

    We have included sample sniffer.html, download.html,flash3.html, flash4.html, flash5.html, flash6.html, flash7.html, andflash8.html files in the ch22/custom_sniffer folder on this book'sCD-ROM. The Flash movie placeholder documents (for example,flash3.html, flash4.html, and so on) do not contain any Flashcontent. Note that the download.html sample file uses theJavaScript and VBScript player detection discussed in the next

    http://www.yourserver.com/download.htmlhttp://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22lev2sec6#ch22lev2sec6http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22lev2sec6#ch22lev2sec6http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22lev2sec6#ch22lev2sec6http://www.yourserver.com/download.html
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    30/104

    section.

    When you have your HTML documents ready, you can load the sniffer.htmldocument into a browser. If the Flash Player is not installed, then the meta tagshould transport the browser location to the download.html URL. If the FlashPlayer is installed, then the Flash ActionScript directs the browser to theappropriate page.

    Detecting the Flash Player with JavaScript and VBScript

    The use of scripts written into an HTML document is also popular for FlashPlayer detection. If you're getting familiar with ActionScript syntax, you'll find thatJavaScript detection code isn't all that complex. JavaScript is a universalscripting language that most 3.0 or higher Web browsers can employ to somecapacity. Microsoft's implementation of JavaScript, called JScript, isn't exactly thesame as JavaScript found in other browsers. For this reason, you can translatesome JavaScript functionality into Microsoft's proprietary Web-scripting language,VBScript.

    On the CD-ROM

    You'll find the HTML, Flash documents, movies, and GIF files forthis section in the ch22/javascript_detection folder of this book'sCD-ROM.

    In this section, we look at how to create an HTML document that checks for thepresence of the Flash Player plug-in with JavaScript, and the Flash ActiveXcontrol with VBScript. We use two images of a traffic light one Flash moviewith a green light animating on and off, and one GIF image with a red light on to display the results of our plug-in and ActiveX detection. Many Web sitesemploy a similar mechanism: Before an HTML page with Flash content can be

    accessed, visitors are presented with a splash screen telling them whether theyhave the Flash Player installed. If they don't have it, they can click a link to getthe plug-in or ActiveX control. As a backup, many splash pages also include alink to bypass the detection in case the detection fails. This link would take thevisitor straight to the HTML document that contains the Flash content.

    Caution The Flash Player can be detected with most JavaScript-enabled Webbrowsers by using the JavaScript array navigator.mimeTypes. The valuefor this array is always empty for Internet Explorer browsers, including IE4.5 on Macintosh. IE 5.0 (or higher) for Macintosh provides support forthis array. While you can use VBScript to detect for IE on Windows,

    there is no script plug-in detection available for IE 4.5 on Macintosh. Youcan however, use the Flash sniffer method, discussed in the previoussections, to detect Flash on IE 4.5 on Macintosh.

    Detecting the Plug-In with JavaScript

    By using JavaScript code, you can set up a testing mechanism that delivers oneof two graphics to the visitor's Web browser.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    31/104

    Copy the script_detection.html document located in the ch22/javascript_detectionfolder of this book's CD-ROM and open it in your preferred text editor (TextEdit,Notepad, BBEdit, and so on), or, even better, in Macromedia Dreamweaver.Look at lines 22 through 27 in the following listing.

    Note The indicates a continuation of the same line of code. It should not bewritten in the actual JavaScript code in the HTML document.

    22. var plugin = 0;23. var activeX = 0;24. var plugin = (navigator.mimeTypes &&

    navigator.mimeTypes["application/x-shockwave-flash"])

    ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0

    25. if (plugin) {

    26. plugin = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)) >= 8

    27. }

    Line 22 initializes a variable plugin to save a value that indicates the presence ofthe Flash Player 8 plug-in on Netscape (or Mozilla, FireFox, IE 5.0 Mac, or AppleSafari). Line 23 initializes a variable called activeX to save a value that indicatesthe presence of the Flash Player 8 ActiveX control. At this point, you assign avalue of 0 to these variables, meaning that the plug in and ActiveX Control arenot installed. This is used for worst-case scenarios in which the user may beusing a version of JavaScript that doesn't interpret the detection code correctly.

    Line 24 is borrowed from the Detect Flash 6 HTML template output from FlashMX (not Flash MX 2004 or Flash 8). It uses the mimeTypes array of the navigatorJavaScript object to determine whether the Flash Player (in any version) isinstalled. If the Flash Player plug-in is installed, the variable plugin is now equalto the value [object Plugin]. If this is true, lines 25 and 26 will execute. Using thedescription property of the Plugin object, you can determine whether the FlashPlayer is the correct version. In this example, you check whether it's greater thanor equal to 8. Notice that you can use a comparison as the value of the pluginvariable. If Flash Player 8 (or higher) is installed, plugin will equal true (or 1); if alower version is installed, plugin will equal false (or 0).

    Creating a Test Object in VBScript

    At this point, if the visitor is using Netscape (or a Mozilla-based browser, on anyoperating system) or Internet Explorer on the Macintosh, the variable plugin willhave a value of either 0 or 1. However, you still need to check for the ActiveXcontrol if the visitor is using Internet Explorer for Windows. Line 13 alreadyinitialized a variable called activeX. Lines 28 through 33 check to see if VBScriptcan create a Flash object in the document:

    Note The indicates a continuation of the same line of code. It should not bewritten in the actual JavaScript code in the HTML document.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    32/104

    28. else if (navigator.userAgent &&

    navigator.userAgent.indexOf("MSIE")>=0 &&navigator.userAgent.indexOf("Windows")>=0){

    29. document.write( \n');30. document.write(on error resume next \n');

    31. document.write(activeX = (IsObject(CreateObject ("ShockwaveFlash.ShockwaveFlash.8")))\n');

    32. document.write(

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    33/104

    detected." If the plugin variable is equal to false and the browser is Netscape 2.0(or Mozilla-compatible) or higher (line 43), then lines 44 and 45 create and tags, depicting a static GIF image of a red traffic light that links to theMacromedia download area. Then, JavaScript creates the HTML text "FlashPlayer 8 plug-in not installed."

    Note The following discussion refers to lines not shown in the code listings for

    this section. Please refer to these lines (and line numbers) within thescript_detection.html document in your preferred text editor.

    Lines 55 through 64 perform the same functionality for Internet Explorer forWindows. If the activeX variable is true, then an tag is written and agreen traffic light animates on. If it's not installed, then a static GIF image of a redtraffic light is displayed. Finally, you should do two more things:

    Tell IE 4.5 (or earlier) Mac users that you can't detect the Flash Player 8plug-in.Tell other users that they can either proceed to the main Flash site, or

    click the appropriate traffic light to download the plug-in or ActiveX control.

    Lines 72 to 75 tell IE 4.5 (or earlier) Mac users that you can't detect their plug-insettings. You can either leave it to them to decide whether they should downloadthe plug-in, or you can direct them to a sniffer movie (discussed in the previoussection) to determine whether the plug-in is installed.

    Lines 76 to 78 check whether either the plug-in or the ActiveX control is installed.If it is, you tell the visitor to proceed to the main Flash site. Note that you'll wantto insert more JavaScript code here that includes a link to your Flash content.

    Lines 79 to 87 check whether the plug-in and the ActiveX control are bothabsent. If neither is installed, you tell them which traffic light (lines 80 to 87) toclick.

    Although you'll most likely want to spruce up the look and feel of this page to suityour particular site, you can use this scripting layout to inform your visitors abouttheir plug-in or ActiveX control installations.

    http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22lev3sec4#ch22lev3sec4http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22lev3sec4#ch22lev3sec4http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22lev3sec4#ch22lev3sec4http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22lev3sec4#ch22lev3sec4http://www.freeopenbook.com/flash8-bible/BBL0201.html#ch22lev3sec4#ch22lev3sec4
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    34/104

    AIM

    Detecting the Operating System.

    PROGRAM

    There are no two ways about it:FlashMX 2004 is a powerful

    development environment for creating fun and engaging

    applications. Yet, there comes a time when you may need a little

    more control of system-related functions such as being able to

    detect the operating system the user is using, launching external

    programs, detecting default file handling applications and

    controlling system windows -- especially when creating

    distributed applications.

    When you are looking to create educational reference

    material, presentations, CD-ROMs or complicated applications,

    Flash will (depending on the complexity of the project) usually

    fulfil the needs of the brief. But there are times when Flash on

    its own just doesn't cut the mustard, and needs a little more

    horsepower to accomplish the desired effect.

    In this article, we'll look at how, by integrating Flash and

    Director, we can query the operating system on which the

    application runs, return information and make decisions based

    on that data. The information presented in this article should

    give you the inspiration to explore the possibilities of Flash and

    Director integration, and give you a taste of what you can

    achieve with a little imagination and flair. The article source files

    can be downloaded by clicking here

    http://www.sitepoint.com/glossary.php?q=F#term_16http://www.sitepoint.com/glossary.php?q=F#term_16http://www.sitepoint.com/glossary.php?q=F#term_16http://www.sitepoint.com/glossary.php?q=F#term_16
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    35/104

    Example Scenario

    You are building an application in Flash that needs to open

    several different file types (spreadsheets, PDFs, presentations,

    executables etc), but in order to make the application as smooth

    as possible, you need to check for the existence of applicationsthat handle the types of files you are trying to open, and act

    accordingly.

    Using Flash to check whether there is a registered file-

    handling application for a given file that you're trying to open is,

    to my mind, extremely difficult -- if not impossible -- without

    third party or bespoke integration tools.

    Enter Stage Left: Director MX /MX 2004!

    I was recently working on a project for a CD-ROM application,

    and decided to create the interface in Flash. There were several

    sections of the application that needed to open PDF files, and I

    included a link to the Adobe Acrobat Reader that was included

    on the CD-ROM. Everything was working fine, until the client

    decided to add features to the project, which included opening

    multiple document types.

    Of course, this presented a new problem: I needed to know

    and inform the user of whether they had installed the application

    required to open the document they'd selected, and Flash just

    wasn't up to the job on its own.

    Rather than scrapping what I'd already written, I decided to

    investigate other methods by which I might retrieve this

    information, and found Director MX 2004 to be the prime

    candidate for the job.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    36/104

    How It Fits Together

    The solution that I came up with was a meld of Flash and

    Director, where I used Flash to create the interface and act as

    the 'stub' to call functions within the Director application, which,

    in turn, was using an Xtra to perform a series of functions.

    While I researched alternative methods for retrieving the

    information, I came across a Director Xtra called 'Buddy API',

    which contains over 140 functions for interfacing with the

    Windows API and Macintosh Toolbox. This was the perfect Xtra

    for the job and, although it is a commercial Xtra, the

    unregistered free version includes two free functions. The Xtra

    contains many functions, some more useful than others. Clickherefor more details.

    Luckily, I could use the unregistered version, as I only needed

    two functions from the Xtra:

    FindApp: Finds the application associated with a file type

    OpenFile: Opens a file using its associated program

    Essentially, the Flash movie is embedded within a director

    application, and, rather than producing a Flash projector, we

    produce a Director Projector that interfaces with the operating

    system via the Director Xtra to check certain criteria, then carry out

    specific functions.

    The flow of information from the Flash interface through

    Director projector for this example is outlined in the diagram below;

    while it's simple, let's take a quick look at the steps involved and

    how the two applications communicate.

    http://www.mods.com.au/http://www.mods.com.au/budapi/http://www.mods.com.au/budapi/http://www.mods.com.au/budapi/http://www.mods.com.au/
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    37/104

    1342_image1 (click to view image)

    Step 1 In the embedded Flash interface, the user clicks a

    button (in the example shown below, it's named openPDFDoco)

    which calls a defined function within the Director application in

    the following format:

    openPDFDoco.onRelease = function() {

    getURL('lingo:FunctionHandler.FunctionName(Parameters)');

    };

    Step 2 The parameters of the file (name, extension, type) are

    passed to the Director movie and a custom function is called,

    which checks via the Buddy API Xtra whether a file handler is

    present for the file we wish to open.

    http://sitepointstatic.com/graphics/sg_001.jpghttp://sitepointstatic.com/graphics/sg_001.jpghttp://sitepointstatic.com/graphics/sg_001.jpghttp://sitepointstatic.com/graphics/sg_001.jpg
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    38/104

    Step 3 The Buddy API Xtra checks to see if a file handler is

    present using the FindApp("file type") function and returns a

    true or false value to the Director Projector.

    Step 4 Based upon whether a file handler is present, the file is

    opened using the OpenFile(filename, windowSize) function ofBuddy API (step 5).

    Step 5 The file handler is verified and the file is opened in the

    relevant application.

    Step 6 If the File Handler is not found for the file we are trying

    to open, we can either trigger an alert within the Director

    projector to inform the user, or we can call a function in Flash.

    Step 7 We call the function to be executed at a specific frame

    in Flash; this could be as simple as moving the playhead to a

    specific frame to inform the user of the missing application for

    the file they're trying to open.

    By planning the behavior and integration of both the Flash SWF

    and the Director Projector, we can have the best of both worlds

    -- an easy-to-maintain application with a powerful interfacethat's capable of many different tasks.

    In the example shown below, I've implemented this

    methodology to create a distributable Director projector. This

    serves as an installer for an application -- both as a

    Macromedia Extension Manager file (*.mxp) and as PDF

    documentation (*.pdf) -- but the basic idea outlined here can

    be used for any number of different projects when you need

    expand the capabilities of Flash.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    39/104

    1342_image2 (click to view image)

    We've now discussed how the application works from a process

    flow point of view, so let's build the application and see how it

    all gels together.

    Creating a Scalable Directory Structure

    As with any development project that uses multiple sources of

    information, we need to establish a working directory structure

    that we can understand easily and use with the minimum of

    confusion; in this case, we're using Flash FLA / SWF / .as files,

    as well as Director Movies / Projectors and PDFs.

    Create a suitable working directory structure as shown below:

    http://sitepointstatic.com/graphics/sg_002.jpghttp://sitepointstatic.com/graphics/sg_002.jpghttp://sitepointstatic.com/graphics/sg_002.jpghttp://sitepointstatic.com/graphics/sg_002.jpg
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    40/104

    1342_image3 (click to view image)

    It's simple, really, but, without the basic groundwork here, we

    could easily get in a mess later when we edit multiple files.

    From the root folder for the application ('Director Application'),

    we have two folders ('Flash Files' and 'ISO'). The Flash

    Interface and relevantActionScriptfiles will reside in the 'Flash

    Files' folder. The 'ISO' folder contains the Director Movie and

    Projector files that we'll create later, as well as the 'Files'

    folder, which will contain the asset files (PDFs) for the

    application.

    Creating the Flash Interface

    You can make your Flash interface as complicated or as simple

    as you like; in this example, we'll create a simple interface with

    a single button (just to keep things simple) that will launch the

    PDF opening process.

    Setting the Scene

    http://sitepointstatic.com/graphics/sg_003.jpghttp://sitepointstatic.com/graphics/sg_003.jpghttp://www.sitepoint.com/glossary.php?q=A#term_25http://www.sitepoint.com/glossary.php?q=A#term_25http://www.sitepoint.com/glossary.php?q=A#term_25http://www.sitepoint.com/glossary.php?q=A#term_25http://sitepointstatic.com/graphics/sg_003.jpghttp://sitepointstatic.com/graphics/sg_003.jpg
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    41/104

    With Flash open, create a new Flash document 450 pixels

    wide by 300 pixels high. Accept the default frame rate and

    click 'OK'.

    Rename the default layer Actions and add below this two

    further layers, called Buttons and Interface.

    Select the first frame of the Interface layer and create an

    interface with a relevant header and other information to

    match your requirements.

    Select the first frame of the Buttons layer and create a new

    button called launchButton. Add the relevant graphic and

    text garnishes to make the button functional. Once you're

    happy with the button, drag an instance from the Library

    Panel into the first frame of the Buttons layer, naming the

    instance launchButton.

    1342_image4 (click to view image)

    We're all done for the first phase of setting up the Flash

    movie. At the moment, there's no ActionScript to control

    the behavior of the button; we'll add this later, once

    we've set up the Director project, imported the SWF, and

    set up the roundtrip environment.

    Save your Flash document as Flash Interface.fla to

    the 'Flash Interface' folder you created earlier, and

    export your SWF (File > Export > Export Movie) as

    Flash Inteface.swf.

    Importing the Flash Interface into Director

    http://sitepointstatic.com/graphics/sg_004.jpghttp://sitepointstatic.com/graphics/sg_004.jpghttp://sitepointstatic.com/graphics/sg_004.jpg
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    42/104

    Now that we've created the basic interface, we need to import it

    into Director and set up a few parameters.

    Setting the Scene

    1) Within Director, create a new Movie (File > New Movie). From

    the 'Movie' tab of the Property Inspector, set the Stage Size to

    450 x 300.

    2) Select File > Import and locate the Flash Interface.swf that you

    have just exported from Flash. Click 'Add' to add it to the import

    list and click 'Import'.

    3) If the Cast window isn't already visible, select Window > Cast to

    show the window and arrange it to your liking.

    4) You should now see the imported Flash movie within the

    5) internal cast window.

    6) Select the Flash movie, and select the 'Member' tab of the

    Property Inspector. Change the 'Name' of the movie to test.

    Within the same tab, click the 'Edit' button and locate the source

    FLA for the SWF file (Flash Interface.fla

    ).

    7) Drag an instance of the imported SWF to the stage and, with the

    Flash movie selected on the stage, edit the 'L' (Left) and 'T'

    (Top) parameters within the 'Sprite' tab of the Property

    Inspector to L:0, T:0.

    This now allows us easily to edit the Flash SWF file via the roundtrip

    methodology from within Director.

    8) Save your Director Movie within the Director Application/ISO

    directory that you created earlier.

    If you now double click the Flash Movie on the stage, it will

    automatically launch Flash for editing. When the file is open within

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    43/104

    Flash, clicking the 'Done' button at the top left of the timeline

    automatically updates the embedded SWF within Director.

    1342_image5 (click to view image)

    This makes life a lot easier; making updates becomes seamless,

    and reduces the chance of Flash SWF edits being lost or

    overwritten.

    Installing the Buddy API Director Xtra

    In order to make full use of what we're working to accomplish here,

    you'll need to install the Buddy API 3.6 Director Xtra. This Xtra isdownloadablehere.

    Once it's downloaded, extract the contents of the .zip or .hqx file

    and copy the budapi.x32 file to your Director Xtras folder, which, in

    Windows and Macintosh, will look something like this:

    Windows - c:\windows\program

    files\macromedia\director mx

    2004\configuration\xtras

    Mac OS X -

    /Users/~USERNAME/Library/Application

    Support/Macromedia/Director MX

    2004/Configuration/Xtras

    Adding the Lingo

    If you were to try and publish your Director Projector now, things

    would look a little odd -- the projector would successfully be

    created but, when you tried to load it, it would open for about a

    second, then close.

    Why?...Well, there's no Lingo orJavaScriptcode that has been

    added within Director. Although it may preview internally within

    http://sitepointstatic.com/graphics/sg_005.jpghttp://sitepointstatic.com/graphics/sg_005.jpghttp://www.mods.com.au/budapi/http://www.mods.com.au/budapi/http://www.sitepoint.com/glossary.php?q=J#term_9http://www.sitepoint.com/glossary.php?q=J#term_9http://www.sitepoint.com/glossary.php?q=J#term_9http://www.sitepoint.com/glossary.php?q=J#term_9http://www.mods.com.au/budapi/http://sitepointstatic.com/graphics/sg_005.jpghttp://sitepointstatic.com/graphics/sg_005.jpg
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    44/104

    Director without any problems, as soon as it's exported into a

    projector, the playback head hits the last frame of the Flash movie

    and quits.

    We need to start adding within Director the code to control this -- a

    simple score script.

    Note: If the Score window is not open make sure it is be selecting

    Window > Score.

    1)Select the first frame of the behavior channel, right click and

    select 'Frame Script'.

    1342_image6 (click to view image)

    2)When the script window opens, name the cast member

    pauseMovie and add the following code:

    on exitFrame

    go to the frame

    end

    http://sitepointstatic.com/graphics/sg_006.jpghttp://sitepointstatic.com/graphics/sg_006.jpghttp://sitepointstatic.com/graphics/sg_006.jpg
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    45/104

    This script simply pauses the movie and gets rid of the annoying

    exiting behavior within the projector.

    If you now preview your projector (File > Publish) you'll see that

    the projector window stays open, and we can move on to add more

    of the control code.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    46/104

    AIM

    Checking the System Language.

    PROGRAM

    Macromedia Flash MX 2004 provides localization capabilitiesusing the Strings Panel to create multi-language text. The Strings Panelenables you to have Flash automatically detect a user's local systemlanguage and use this as the default for displaying localized textstrings. Sometimes developers may want to provide, by way of a menuselection in the Flash movie, a user-specified language selection that

    can be used instead of the default system language to substitute the

    localized text strings.

    Prerequisites

    In order to get the most out of this TechNote, an understandingof the Flash MX 2004 Strings Panel functionality is required. Informationon using the Strings Panel to provide localized text objects can be foundin the "Using the Strings panel to author multi-language text" section ofthe Flash Help. Additionally, an understanding of ActionScriptprogramming and debugging is needed since you will modify a sourceActionScript file and add new functions that must be called from your

    FLA.

    Strings panel settings

    Under its Settings button, the Strings Panel has a user selectableoption to replace the dynamic text objects with localized strings. In thisexample we will be using theruntime mode. In the Strings panel

    settings, make the selection for runtime below:

    Author time: Uncheck "Insert ActionScript for automatic languagedetection". You have to select the stage language and publish. Thepublished SWF will always use the stage language strings for thedynamic texts.Runtime: Check "Insert ActionScript for automatic languagedetection". You have to make sure the external XML files with thelocalized strings are available with the published SWF. These external

    XML files are written out by the Flash authoring tool and reside in thesame directory as the published SWF. The Flash player detectsSystem.capabilities.language and loads the XML file that matches the

    local user's language.

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    47/104

    ActionScript Implementation

    You will need to modify and add new methods in the Locale.asfile. Follow the steps below to modify the Locale.as file located in theuser configuration path (do not use the original Locale.as file located

    under the application path).

    There are actually two locations that developers can choose toplace the newly modified Locale.as file: in the user path (which will

    affect all projects) or in the local path (which affects the currentdocument only). This TechNote will discuss the user path location. Formore information about the local path location, refer to the Additional

    Informationat the end of this document.

    To modify Locale.as:

    1. Open up the Locale.as file located at:

    Windows 2000 or XP:\Documents and Settings\\Local Settings\Application Data\Macromedia\Flash MX2004\en\Configuration\Classes\mx\lang\Locale.as

    Windows 98SE:\Windows\Application Data\Macromedia\Flash MX 2004\en\Configuration\Classes\mx\lang\Locale.as

    Mac OS X:

    http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19097#addinfo#addinfohttp://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19097#addinfo#addinfohttp://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19097#addinfo#addinfohttp://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19097#addinfo#addinfohttp://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19097#addinfo#addinfohttp://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19097#addinfo#addinfo
  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    48/104

    :Users::Library:Application Support:Macromedia:Flash MX2004:en:Configuration:Classes:mx:lang:Locale.as

    2. In Locale.as, add a new public method:3. static function setXMLLang(langCode:String):Void4. {5. xmlLang = langCode;6. }

    Separate the existing initialize() function into two functions by creatinga new start() function and copying code from the original initialize()

    function:

    static function initialize():Void{

    xmlDoc = new XML();xmlDoc.ignoreWhite = true;

    xmlDoc.onLoad = function(success:Boolean){

    onXMLLoad(success); // parse the XMLcallback.call(null, success);

    }}

    static function start():Void{

    var langCode:String = xmlLang;if(xmlMap[xmlLang] == undefined) {

    langCode = defaultLang;}

    currentXMLMapIndex = 0;xmlDoc.load(xmlMap[langCode][0]);

    }

    7. Save and close Locale.as.8. To utilize the changes you just made in Locale.as, add these 2 lines as

    a frame action to the FLA file. You only need to call them once and thenew language setting will apply to the whole movie:

    9.// make sure the there is a corresponding10.///_.xml file in the SWF root

    directory11. var newLang:String = ""; //for example "de"12. mx.lang.Locale.setXMLLang(newLang);

    13.// begin replacing the dynamic texts with strings from the xml filemx.lang.Locale.start();

  • 7/31/2019 Shaik Bilal Ahmed Mad Lab Programs

    49/104

    Authoring Implementation and Debugging

    There is a limitation that developers need to be aware of whenusing this technique. All dynamic text fields that use the Strings Panelhave to exist in or before the frame where the language switching codeis executed. In cases where it is not desirable to show a text field priorto language selection, it may be necessary to author text fields with the

    visibility set to false.

    A useful debugging technique to show correct implementation isto add trace statements to the modified Locale.as file to ensuremethods are being called in the correct order. Traces can be added tothese Locale.as methods:

    static function addDelayedInstance() private static functiononXMLLoad()

    private static function assignDelayedInstances()

    Successful implementations will result in traces in this order:

    addDelayedInstanceonXMLLoadassignDelayedInstances

    Notes

    Unless you setup a local document path for the modified Locale.as, thechanges you make to the source Locale.as will apply to all FLA files inall your projects. Since mx.lang.Locale.initialize() no longer containsall of its original code, you will have to call mx.lang.Locale.start(); in

    other FLA files even if you do not plan to define your own language.See theAdditional Information below.When modifying the Locale.as file, be sure to leave a space or linereturn between the function return type and the opening brace inorder to avoid syntax error messages in the authoring environment:

    static function start():Void {...}

    If you want to revert back to the original behavior, simply delete themodified Locale.as file in your user configuration folder. The originalfile at "\en\First Run\Classes\mx\lang" will be copiedover to your user configuration folder the next time you launch Flash.Be aware that there is a dependency that the timestamp of modifiedAS files must precede the timestamp of the compiled ASO files. It maybe necessary to manually delete yourmx.lang.Locale.aso file for the

    changes to take effect. For more information, see Compiler cachesexternal class files ( TechNote 19045).

    http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19097#addinfo#addinfohttp://kb.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_19045http://kb.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_19045http://kb.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_19045http://kb.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_19045http://kb.adobe.com/cfusion/kno