PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
e.targetName help
A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: e.targetName help

  1. #1
    Senior Member
    Join Date
    Jan 2010
    Posts
    141

    e.targetName help

    Hello,

    I am working on a project and have a grid of boxes, that when clicked will make a movie clip's visibility true. To help reduce the amount of code I need to write I was hoping that I could use one function that will work for each item in the grid. I was thinking that If I named the MC with a simular name as the event target's name that could work for the one function. I've never used e.targetName (or is it e.target.name) before, and apparently I don't know the proper way to use, or if this will even work for me. I've tried several methods:

    1. "e.targetName + A" since I know you can't have 2 items with same instance name I tried to call the name of event's item and add something to it. ERROR

    2 so then I decided if I put all of the MC I wanted to open in a container movie clip. That way I could have items with same instance name. "mcBOX.e.targetName.visible = true" ERROR

    3. this is when I tried the google and could not find an answer.

    Please let me know if I am crazy to think this will work, and/or another method that will work. Thank you all!
    Last edited by word2yerMom; 06-14-2012 at 11:09 AM. Reason: typo

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    That is exactly how I would do it, just with some syntax changes. If you name each of the grids with a similar name but some unique identifier then when the function is called it is called through the EVENT handler which contains an image of what was selected.

    Your function may look something like this:
    Actionscript Code:
    function clickHandler(evt:MouseEvent):void
    {
       var selectedGrid:MovieClip = evt.currentTarget;
       
        if (selectedGrid.name == "blah")
            [I]this do this here based on it.[/I]

        //You can also use a switch statement
        switch(selectedGrid.name)
        {
            case "grid1":
                //Do something
                break;
            case "grid2":
                //Do something else
                break;

        }
    }
    That should minimize your coding.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Senior Member
    Join Date
    Jan 2010
    Posts
    141
    I did not actually create a true grid, but arranged items in a grid. I called each item by row (a-e) and columns (a-e); so position 1 is aa_mc to the right is ba_mc and below is ab_mc. I'm not sure how to make the code you gave me work with that.

  4. #4
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Well what I gave you was pseudo code and not completely correct to work. I guess the biggest thing to get first is what happens AFTER the click. If the actions are different based on the grid that happens outside of the grid, then you need to identify who it is and that could be a length list. If the actions are similar then you just need to pass the name around so the inner class function for that grid object is called. So the question is what happens when the user clicks a grid element.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  5. #5
    Senior Member
    Join Date
    Jan 2010
    Posts
    141
    I am making a fake Jeopardy game. The "grid" is the dollar amounts (frame 1 shows dollars; frame 2 is blank square). When you click on a dollar amount, the MC goes to frame 2 and ends the button mode. I also pull up a shade to hide game board. Then a box with the answer is suppose to pop up.

    Here is the code I have right now:
    Actionscript Code:
    aa_mc.gotoAndStop(1);
    aa_mc.buttonMode = true;
    aa_mc.addEventListener(MouseEvent.CLICK, showAnswer);

    function showAnswer(e:MouseEvent):void{
        e.target.gotoAndStop(2);
        e.target.buttonMode = false;
        shade_mc.visible = true;
            // this is where I'm trying to write one line of code that will open the correct answer so for aa_mc ; aa_mcAns's visibility gets set to true. I don't know if I should scrap the visibility and add dynamically with code or what.
    }

  6. #6
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    So whenever they click on a grid it will take them to a different frame?
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  7. #7
    Senior Member
    Join Date
    Jan 2010
    Posts
    141
    It was originally not going to, but that is a rout I am exploring that avenue now using

    gotoAndStop("e.target.name");

    however I am getting ArgumentError: Error #2109: Frame label e.target.name not found in scene Scene 1.

    am researching that now.

  8. #8
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Well, you have to do something a little different. There are three options I can see that are quick. One would be to add a switch or if statement that looks for the name and when found moves to the appropriate frame number. This can be long an cumbersome.

    Now the remaining two ideas have promise but depends on the route you want to take.

    The first is added a variable to all of your grids. Something like frameID. In this frameID variable you would store the corresponding frame number, so when the grid is clicked, you can use the following to move to the correct frame number

    gotoAndStop(e.currentTarget.frameID);

    This takes a little tweaking and you have to navigate to each of the grids to do it. It works well if you are dynamically (by code) building the grid in which as a grid is placed on the stage the frame information is automatically added.

    The last way would be to use an array. You have an array that has both the grid name and its associated frame number. This has the benefit of being able to change the frame information quickly and still see all other corresponding frame ids.

    Using this way, you may need to build a function that searches the array list for the appropriate grid name and return the associated id. This way this would work

    gotoAndStop(getFrameID(e.currentTarget.name));

    Each have their own pros and cons, but find one that works best for you. I usually try to go with one with minimal coding, cause that is how I roll. Does that make sense?
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  9. #9
    Senior Member
    Join Date
    Jan 2010
    Posts
    141
    I'm thinking a series of if statements could work for me IF they can be used like this...

    Actionscript Code:
    if (e.target.name == aa_mc){
    gotoAndStop("aaFrameName");
    }

    I know I would have to add an if statement for each grid item, but it would still save me from having to retype all the other stuff. will this work?

  10. #10
    Senior Member
    Join Date
    Jan 2010
    Posts
    141
    ok that does not seam to work. How can you link items in a array (option 3)?

    I did not dynamically build the grid, so I'm thinking options 3 would work better than 2. I'm about to give up and just hard code it all. : (

  11. #11
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Wait, the if statement should work without a problem. Can you post the code from that section. Make sure you've provided an instance name for each of the grid MC.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  12. #12
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813

    Thumbs up A little Confusing

    I know what I am explaining can be a little confusing, so I threw together a piece of code example that simulates your jeopardy format. I am, by no means, suggesting that you build or proceed in the direction that I've taken. This is simply a method I used and the best way I can see on explaining the process.

    I hope this help. If you have any questions, let me know. BTW, I like using .AS files verses loading AS3 content into my layers, I'm strange like that.
    Last edited by samac1068; 06-15-2012 at 12:09 PM.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  13. #13
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813

    Another Update

    Okay, I was a little bored and worked out the code a little more. I wouldn't open and pull any methods out from the attach, but rather come up with a method and compare it to mine. I don't proclaim every using the best method, but I found a way that is comfortable for me. That is the great thing about programming, more than one way to skin any component.
    Attached Files Attached Files
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

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