A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: access to movieclips through linkage id's (F8)

  1. #1
    Member
    Join Date
    Sep 2007
    Posts
    32

    access to movieclips through linkage id's (F8)

    I have been attemting to access a set of btns that I've placed on stage who are attached to a group of empty movieclips inside of another Movieclip.

    Everything else is working (thanks silentweed). My main problem is trying to give these btns actions and am just going in circles. This code is inside movieclip q1 with a identifier of q1(on the first frame).

    Array.prototype.randomize = function() {
    var i = this.length;
    if (i == 0) return;
    while (--i) {
    var j = Math.floor(Math.random()*(i+1));
    var tmp1 = this[i];
    var tmp2 = this[j];
    this[i] = tmp2;
    this[j] = tmp1;
    }
    return this;
    }

    var arr = new Array("q1_ans1","q1_ans2", "q1_ans3", "q1_ans4", "q1_ans5");
    arr.randomize();
    trace(arr[0]);
    trace(arr[1]);
    trace(arr[2]);
    trace(arr[3]);
    trace(arr[4]);
    trace(arr.length);
    //place randomized btns to existing empty mc's
    this.empty1.attachMovie(arr[0],arr[0],1);
    this.empty2.attachMovie(arr[1],arr[1],2);
    this.empty3.attachMovie(arr[2],arr[2],3);
    this.empty4.attachMovie(arr[3],arr[3],4);
    this.empty5.attachMovie(arr[4],arr[4],5);
    //btn actions
    ???

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Try this
    PHP Code:
    Array.prototype.randomize = function() {
    var 
    this.length;
    if (
    == 0) return;
    while (--
    i) {
    var 
    Math.floor(Math.random()*(i+1));
    var 
    tmp1 this[i];
    var 
    tmp2 this[j];
    this[i] = tmp2;
    this[j] = tmp1
    }
    return 
    this;
    }

    var 
    arr = new Array("q1_ans1","q1_ans2""q1_ans3""q1_ans4""q1_ans5");
    arr.randomize();
    trace(arr[0]);
    trace(arr[1]);
    trace(arr[2]);
    trace(arr[3]);
    trace(arr[4]);
    trace(arr.length);
    //place randomized btns to existing empty mc's
    var button1:MovieClip this.empty1.attachMovie(arr[0],arr[0],1);
    var 
    button2:MovieClip this.empty2.attachMovie(arr[1],arr[1],2);
    var 
    button3:MovieClip this.empty3.attachMovie(arr[2],arr[2],3);
    var 
    button4:MovieClip this.empty4.attachMovie(arr[3],arr[3],4);
    var 
    button5:MovieClip this.empty5.attachMovie(arr[4],arr[4],5);
    //btn actions
    this["button1"].onRelease = function() {
        
    trace("You clicked "+this);
    }
    this["button2"].onRelease = function() {
        
    trace("You clicked "+this);
    }
    this["button3"].onRelease = function() {
        
    trace("You clicked "+this);
    }
    this["button4"].onRelease = function() {
        
    trace("You clicked "+this);
    }
    this["button5"].onRelease = function() {
        
    trace("You clicked "+this);


  3. #3
    Member
    Join Date
    Sep 2007
    Posts
    32
    unfortunately no... didn't work.

    Maybe I should mention this too....

    When the btn is clicked it needs to goto frame two of the same timeline that that btn is on... dunno if I am overthinking this and/or maybe there is a easy way to just put script on the btn itself.

  4. #4
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Does this work?
    button1.onRelease = function() {
    trace("You clicked "+this);
    }

    If not, can you attach your files or email me them? sstalder at gmail

  5. #5
    Member
    Join Date
    Sep 2007
    Posts
    32
    no dice.

  6. #6
    Member
    Join Date
    Sep 2007
    Posts
    32
    might be because that is calling to the variable which is attaching the randomized list of btns not the btn itself....

    i am really looking for a function that will take the linkage names and give me a instance name to reference.

  7. #7
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    What exactly is q1_ans1 (items in the array)? Are these movieclips?

    And are you able to post your fla file?

  8. #8
    Member
    Join Date
    Sep 2007
    Posts
    32
    can't really send the file... it is a corporate client. The "q1_ans1", "q1_ans2", ect. ect. are btns that are dynamically placed randomly to 5 empty movieclips. These empty movieclips are inside another movieclip "q1". Which is dynamically placed on another movieclip on the main timeline.

    Really sounds like a mess when you type it all out.

  9. #9
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Try this one:
    PHP Code:
    Array.prototype.randomize = function() { 
        var 
    this.length
        if (
    == 0) return; 
        while (--
    i) { 
            var 
    Math.floor(Math.random()*(i+1)); 
            var 
    tmp1 this[i]; 
            var 
    tmp2 this[j]; 
            
    this[i] = tmp2
            
    this[j] = tmp1
        } 
        return 
    this


    var 
    arr = new Array("q1_ans1","q1_ans2""q1_ans3""q1_ans4""q1_ans5"); 
    arr.randomize(); 
    //place randomized btns to existing empty mc's 
    this.empty1.attachMovie(arr[0],arr[0],1); 
    this.empty2.attachMovie(arr[1],arr[1],2); 
    this.empty3.attachMovie(arr[2],arr[2],3); 
    this.empty4.attachMovie(arr[3],arr[3],4); 
    this.empty5.attachMovie(arr[4],arr[4],5); 

    //btn actions 
    this.empty1[arr[0]].onRelease = function() { 
        
    trace("You clicked " this); 

    this.empty2[arr[1]].onRelease = function() { 
        
    trace("You clicked " this); 

    this.empty3[arr[3]].onRelease = function() { 
        
    trace("You clicked " this); 

    this.empty4[arr[3]].onRelease = function() { 
        
    trace("You clicked " this); 

    this.empty5[arr[4]].onRelease = function() { 
        
    trace("You clicked " this); 


  10. #10
    Member
    Join Date
    Sep 2007
    Posts
    32
    still not working... that is still calling to the instance name which doesn't exist. It is the linkage ID that I need to call too

  11. #11
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Is this actionscript inside your .swf file or are you doing an include?

    And aren't your instance names q1_ans1 - 5?

    If you can't show your swf you may have to just type out your structure and layers so we can get a better idea of your layout. I am trying to reference items based off your code, which appears to not be working.

  12. #12
    Member
    Join Date
    Sep 2007
    Posts
    32
    they are movieclips brought in dynamically so they don't have instance names... they have their linkage i.e. - attachMovie("symbol name", "new ID name", level);

    the names in the array are just names... so I could create a randomized effect

  13. #13
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Ok last thing I request of you to hopefully fix this:

    (Please use this code and paste all of the trace data and all errors you recieve)
    PHP Code:
    Array.prototype.randomize = function() { 
        var 
    this.length
        if (
    == 0) return; 
        while (--
    i) { 
            var 
    Math.floor(Math.random()*(i+1)); 
            var 
    tmp1 this[i]; 
            var 
    tmp2 this[j]; 
            
    this[i] = tmp2
            
    this[j] = tmp1
        } 
        return 
    this


    var 
    arr = new Array("q1_ans1","q1_ans2""q1_ans3""q1_ans4""q1_ans5"); 
    arr.randomize(); 
    //place randomized btns to existing empty mc's 
    this.empty1.attachMovie(arr[0],arr[0],1); 
    this.empty2.attachMovie(arr[1],arr[1],2); 
    this.empty3.attachMovie(arr[2],arr[2],3); 
    this.empty4.attachMovie(arr[3],arr[3],4); 
    this.empty5.attachMovie(arr[4],arr[4],5); 

    //btn actions
    trace("_root >> " _root);
    trace("_parent >> " _parent);
    trace("this >> " this);
    trace("this.empty1 >> " this.empty1);
    trace("this.empty2 >> " this.empty2);
    trace("this.empty3 >> " this.empty3);
    trace("this.empty4 >> " this.empty4);
    trace("this.empty5 >> " this.empty5);
    trace("this.empty1[arr[0]] >> " this.empty1[arr[0]]);
    trace("this.empty1[arr[1]] >> " this.empty1[arr[1]]);
    trace("this.empty1[arr[2]] >> " this.empty1[arr[2]]);
    trace("this.empty1[arr[3]] >> " this.empty1[arr[3]]);
    trace("this.empty1[arr[4]] >> " this.empty1[arr[4]]);

    /*
    this.empty1[arr[0]].onRelease = function() { 
        trace("You clicked " + this); 

    this.empty2[arr[1]].onRelease = function() { 
        trace("You clicked " + this); 

    this.empty3[arr[3]].onRelease = function() { 
        trace("You clicked " + this); 

    this.empty4[arr[3]].onRelease = function() { 
        trace("You clicked " + this); 

    this.empty5[arr[4]].onRelease = function() { 
        trace("You clicked " + this); 

    */ 

  14. #14
    Member
    Join Date
    Sep 2007
    Posts
    32
    this chunk of trace functions helps out a ton.... thanks so much. I really appreciate the time you spent helping out. Finally starting grasping the whole AS language this past week and it is hard to keep in mind little tricks like this...

    ... this is what I got by the way...

    _root >> _level0
    _parent >> _level0.instance12.q1_empty
    this >> _level0.instance12.q1_empty.q1
    this.empty1 >> _level0.instance12.q1_empty.q1.empty1
    this.empty2 >> _level0.instance12.q1_empty.q1.empty2
    this.empty3 >> _level0.instance12.q1_empty.q1.empty3
    this.empty4 >> _level0.instance12.q1_empty.q1.empty4
    this.empty5 >> _level0.instance12.q1_empty.q1.empty5
    this.empty1[arr[0]] >> _level0.instance12.q1_empty.q1.empty1.q1_ans3
    this.empty1[arr[1]] >> undefined
    this.empty1[arr[2]] >> undefined
    this.empty1[arr[3]] >> undefined

  15. #15
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Im so sorry I typoed in the code, one more time for this chunk:

    And can you also click each button once for me so I can see that trace.

    Im glad I am able to help, I love this stuff! It is way too addicting!
    PHP Code:
    //btn actions
    trace("_root >> "+_root);
    trace("_parent >> "+_parent);
    trace("this >> "+this);
    trace("this.empty1 >> "+this.empty1);
    trace("this.empty2 >> "+this.empty2);
    trace("this.empty3 >> "+this.empty3);
    trace("this.empty4 >> "+this.empty4);
    trace("this.empty5 >> "+this.empty5);
    trace("this.empty1[arr[0]] >> "+this.empty1[arr[0]]);
    trace("this.empty2[arr[1]] >> "+this.empty2[arr[1]]);
    trace("this.empty3[arr[2]] >> "+this.empty3[arr[2]]);
    trace("this.empty4[arr[3]] >> "+this.empty4[arr[3]]);
    trace("this.empty5[arr[4]] >> "+this.empty5[arr[4]]);


    this.empty1[arr[0]].onRelease = function() { 
        
    trace("You clicked " this); 
    }
    this.empty2[arr[1]].onRelease = function() { 
        
    trace("You clicked " this); 
    }
    this.empty3[arr[3]].onRelease = function() { 
        
    trace("You clicked " this); 
    }
    this.empty4[arr[3]].onRelease = function() { 
        
    trace("You clicked " this); 
    }
    this.empty5[arr[4]].onRelease = function() { 
        
    trace("You clicked " this); 

    Do you have aim, yahoo or gmail messenger? This would be much easier.

  16. #16
    Member
    Join Date
    Sep 2007
    Posts
    32
    I know what you mean about the addiction... Here is the output after the change and I did click all the btns. Doesn't look like it worked.


    _
    PHP Code:
    root >> _level0
    _parent 
    >> _level0.instance12.q1_empty
    this 
    >> _level0.instance12.q1_empty.q1
    this
    .empty1 >> _level0.instance12.q1_empty.q1.empty1
    this
    .empty2 >> _level0.instance12.q1_empty.q1.empty2
    this
    .empty3 >> _level0.instance12.q1_empty.q1.empty3
    this
    .empty4 >> _level0.instance12.q1_empty.q1.empty4
    this
    .empty5 >> _level0.instance12.q1_empty.q1.empty5
    this
    .empty1[arr[0]] >> _level0.instance12.q1_empty.q1.empty1.q1_ans3
    this
    .empty2[arr[1]] >> _level0.instance12.q1_empty.q1.empty2.q1_ans4
    this
    .empty3[arr[2]] >> _level0.instance12.q1_empty.q1.empty3.q1_ans5
    this
    .empty4[arr[3]] >> _level0.instance12.q1_empty.q1.empty4.q1_ans2
    this
    .empty5[arr[4]] >> _level0.instance12.q1_empty.q1.empty5.q1_ans1 

  17. #17
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    I am out of ideas, the code seems fine because all the objects are able to be seen and I am calling the movieclips by the proper names. hmm.

    When you mouseover the buttons does the mouse cursor change? Possibly it's an issue with the depth of the movies.

    Try to modify this:
    PHP Code:
    //place randomized btns to existing empty mc's 
    this.empty1.attachMovie(arr[0], arr[0], _root.getNextHighestDepth());
    this.empty2.attachMovie(arr[1], arr[1], _root.getNextHighestDepth());
    this.empty3.attachMovie(arr[2], arr[2], _root.getNextHighestDepth());
    this.empty4.attachMovie(arr[3], arr[3], _root.getNextHighestDepth());
    this.empty5.attachMovie(arr[4], arr[4], _root.getNextHighestDepth());

    // If this fails try this.empty1.getNextHighestDepth() and so on, but I don't think that should be necessary 

  18. #18
    Member
    Join Date
    Sep 2007
    Posts
    32
    the btns are attaching fine... for some reason the onRelease function() isn't executing the trace

  19. #19

  20. #20
    Member
    Join Date
    Sep 2007
    Posts
    32
    I uploaded a version if you wanna check it out.
    Attached Files Attached Files

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