A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Using if statement on a clip

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    11

    Using if statement on a clip

    Hello....

    i am working on a project where i am using the attach movie to load a clip from the library..

    Actionscript Code:
    regionListener.change = function(){
        attachMovie(_level0.frameName + cbRegions.value,"clip",2);

    Now i need to hide the sample_mc that is already on stage only if a clip is loaded... on the else statement sample_mc should be visible again..

    So...i dont know how to say that in AS2 language...
    Actionscript Code:
    If clip is loaded , sample_mc._visible = false; else sample_mc._visible = true;

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    im not sure HOW to check for an attachedMovie.. it just does it automatically unless you coded something..

    I suppose you could check fora property or instance name?

    I guess Im not following how or why the clip wouldnt be attached if you code it to? its not loading external content..

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    11
    Hello whispers...thanks for your answer


    The project is loading clips from a combobox named cbRegions

    the code looks like this

    Actionscript Code:
    var regionListener:Object = new Object ();
    cbRegions.addEventListener ("change",regionListener);
    regionListener.change = function(){
        attachMovie(_level0.frameName + cbRegions.value,"clip",2);
        cbSize.setSelectedIndex(0);
        cbIndustry.setSelectedIndex(0);
    }

    I have to to know which region is curently loaded or selected in the combobox so that i can programm it to hide/show certain movie clips when user click back/next button....

    Only way to check i guess is with a if statement for the combobox and i tried it with no luck...


    Now code looks something like this :

    Actionscript Code:
    //setting the variables for the combobox
    var eventSource = eventObj.target;
    var theSelectedItem = eventSource.selectedItem;
    var theSelectedItemLabel = theSelectedItem.label;

    //The movie clip that includes the next and back buttons
    mcNav.mcBack.onRelease = function (){
        gotoAndStop(_currentframe-1)
        q6global._visible = true;
        if (theSelectedItemLabel == "Spain")
        q6global._visible = false ;
    };


    var regionListener:Object = new Object ();
    cbRegions.addEventListener ("change",regionListener);
    regionListener.change = function(){
        attachMovie(_level0.frameName + cbRegions.value,"clip",2);
        cbSize.setSelectedIndex(0);
        cbIndustry.setSelectedIndex(0);
    }

  4. #4
    Junior Member
    Join Date
    Apr 2011
    Posts
    11
    HA! Got it...

    here is the correct code


    Actionscript Code:
    onEnterFrame = function (){
        q6global._visible = true;
      if (cbRegions.selectedItem.label == "Spain") {    
           q6global._visible = false;
         }
         else if (cbRegions.selectedItem.label == "United Kingdom") {    
             q6global._visible = false;  
        }

  5. #5
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    I would use the onChange event... instead of a onEnterFrame.

    actionscript Code:
    // Add Items to Combo Box.
    regions_cb.addItem({data:1, label:"Spain"});
    regions_cb.addItem({data:2, label:"United Kingdom"});
    regions_cb.addItem({data:3, label:"United States"});

    // Add event listener and event handler function.
    var cbListener:Object = new Object();
    cbListener.change = function(evt_obj:Object):Void  {
        var currentlySelected:Object = evt_obj.target.selectedItem;
        trace(evt_obj.target);
        trace("data: " + currentlySelected.data);
        trace("label: " + currentlySelected.label);
       
        //conditional check using case/switch statement
        switch (currentlySelected.label) {
            case "Spain" :
                trace("you chose spain");
                //do whatever you want here when spain is chosen
                q6global._visible = false ;
                break;
            case "United Kingdom" :
                trace("you chose uk");
                //do whatever you want here when united kingdom is chosen
                break;
            case "United States" :
                trace("you chose usa");
                //do whatever you want here when united states is chosen
                break;
            default :
                trace("default when something/anything other than above is chosen");
                break;
        }

    };
    regions_cb.addEventListener("change",cbListener);

  6. #6
    Junior Member
    Join Date
    Apr 2011
    Posts
    11
    Hi whispers.... will give that solution a go because it seems interesting the way it works,

    Thanks for the solution!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center