A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: attachMovie

  1. #1
    always learning
    Join Date
    Sep 2004
    Location
    somewhere over the rainbow
    Posts
    90

    attachMovie

    Hello all,

    I'm new to the attachMovie world and am having trouble adding a unique link to all of the new movies that are created.

    I placed comment tags where I am having trouble.
    If there is another way of doing this besides the way i'm trying please help me out

    PHP Code:

    var links=new Array();
    links[0]="link1";
    links[1]="link2";
    etc...

    var 
    spacing:Number=13;

    for(var 
    i=0;i<test.length;++i){
        
        var 
    name:String="view"+i+"_mc";
        var 
    x:Number=i*spacing;
        
        
    this.view_mc.attachMovie("viewer",name,i);
        
    this.view_mc[name]._x=x;
        
        
    // THIS DOESN'T WORK
        
    this.view_mc[name].onPress=function(){
            
           
    // "texto" is a dynamic text box used for testing the script
            
    _root.large_mc.texto=links[i]; 
            
        }
        

        



    What am I doing wrong or not doing?

    Thanks in advance,

    Loo
    Loo fe le vi

  2. #2
    Senior Member
    Join Date
    Jun 2007
    Location
    Nottingham, England
    Posts
    203
    The way you've structured you're array notation is wrong. It van only be used to access entries directly from an array.

    So Instead of
    PHP Code:
    this.view_mc[name
    You would have to use the eval function or it's equivalent in array notation:
    PHP Code:
     this.eval("view_mc"+name).onPress=function(){ 
    or

    PHP Code:
     this["view_mc"+name].onPress=function(){ 
    So make sure you amend that and you should be on your way! - Chris.

  3. #3
    always learning
    Join Date
    Sep 2004
    Location
    somewhere over the rainbow
    Posts
    90
    Thanks,

    But it didn't work
    I will keep trying what you suggested.. sometimes I'm just blind to my typos.

    Thanks again,

    Loo
    Loo fe le vi

  4. #4
    always learning
    Join Date
    Sep 2004
    Location
    somewhere over the rainbow
    Posts
    90
    Withe the code you gave me the onPress is disabled.

    Any ideas? Please help!

    Thanks,

    Loo
    Loo fe le vi

  5. #5
    Senior Member
    Join Date
    Jun 2007
    Location
    Nottingham, England
    Posts
    203
    Hey again. The more I look at your code, it doesn't seem to make any sense. There's lots of little mismatched bits and bobs and such.

    Your loop is testing the condition if "i" is less than the length of an array called "test", but the only array you have is called links.

    Explain to me exactly what you're trying to do with you're attaching movies and I'll try to help you out.

    - Chris

  6. #6
    always learning
    Join Date
    Sep 2004
    Location
    somewhere over the rainbow
    Posts
    90
    lol SOrry bout that.


    Typo!

    Its for the links:

    PHP Code:
    var links=new Array();
    links[0]="Cool";
    links[1]="Sweet";
    links[2]="Yeah";



    var 
    spacing:Number=13;

    for(var 
    i=0;i<links.length;++i){
        
        var 
    name:String="view"+i+"_mc";
        var 
    x:Number=i*spacing;
        
        
    this.view_mc.attachMovie("viewer",name,i);
        
    this.view_mc[name]._x=x;
        
        var 
    link=links[i];
        
    this.view_mc[name].onPress=function(){
            
            
    _root.large_mc.texto=link;
            
            
        }
        

        

    I changed things around. It was "test" before, but I wanted to be clear and changed it to links but forgot to change it in the loop.



    I tried calling a function like this too:

    PHP Code:
    this.view_mc[name].onPress=function(){
            
            
    linkClicked(link);
            
            
        } 
    But both methods just give me the last array value which is "Yeah".

    What am I doing wrong. Please don't give up on me! :P


    Loo
    Loo fe le vi

  7. #7
    Senior Member
    Join Date
    Jun 2007
    Location
    Nottingham, England
    Posts
    203
    That still makes no sense. The name variable is a string and you're trying to access that value in an array so it must be a number. Plus there IS no array called "view_mc" it's a movieclip. To address a dynamically named object or MC you must use the two methods I posted earlier.

    In spite of all that though, I don't understand what you're trying to do with this code. Explain, from scratch; what you're trying to achieve and I'll see if I can help!

    - Chris

  8. #8
    always learning
    Join Date
    Sep 2004
    Location
    somewhere over the rainbow
    Posts
    90
    Oops didnt read the last line if your post.

    I'm trying to add additional views for my portfolio. I would like to do this dynamically. (<< self taught freak).

    The info to populate the amount of views can either come from an Array or Database (MYSQL). In this case an Array.

    I got the amount of "additional views" buttons (MovieClips) to display, but I cant get the appropriate links to pass on to each newly created MovieClip.

    So once the user clicks on a new MovieClip they get a new view.

    Sorry about the rushy description, but I'm desperate to get this over with

    Thanks for the help.

    Loo
    Loo fe le vi

  9. #9
    always learning
    Join Date
    Sep 2004
    Location
    somewhere over the rainbow
    Posts
    90
    For example:

    I need to create new portfolio views depending on what the "links" array returns:

    1.-
    link1[0]="One";
    link2[1]="Two";
    link3[2]="Three";
    Etc...

    2.-Make the additional movies for each link using attachMovie().

    3.-Assign a link to each movieClip created.
    Loo fe le vi

  10. #10
    Senior Member
    Join Date
    Jun 2007
    Location
    Nottingham, England
    Posts
    203
    Well your rushy description didn't really help matters :P But I tried to correct your code from what I think you're trying to do.

    Try this..
    PHP Code:
    for (var 0i<links.length; ++i) {
        var 
    newName:String "view"+i+"_mc";
        var 
    newX:Number i*spacing;
        
    this.view_mc.attachMovie("viewer"newNamei);
        
    this["view_mc"+newName]._x newX;
        var 
    link links[i];
        
    this["view_mc"+newName].onPress = function() {
            
    _root.large_mc.texto link;
        };


  11. #11
    always learning
    Join Date
    Sep 2004
    Location
    somewhere over the rainbow
    Posts
    90
    Oh and im using FLash MX 2004!



    Loo
    Loo fe le vi

  12. #12
    always learning
    Join Date
    Sep 2004
    Location
    somewhere over the rainbow
    Posts
    90
    It didnt work.
    So, I changed the code to read like this (view comment tags):

    PHP Code:
    for (var 0i<links.length; ++i) {
        var 
    newName:String "view"+i+"_mc";
        var 
    newX:Number i*spacing;
        
    this.view_mc.attachMovie("viewer"newNamei);

       
    // CHANGED
        
    this.view_mc[newName]._x newX;
        var 
    link links[i];
        
    // CHANGED
        
    this.view_mc[newName].onPress = function() {
            
    _root.large_mc.texto link;
        }

    The above worked for positioning, but still only the last link "Yeah" is passed.

    I really appreciate your help. Thanks again.

    Loo
    Loo fe le vi

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