dcsimg
A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: -function+fun

Hybrid View

  1. #1
    Member
    Join Date
    May 2006
    Posts
    48

    -function+fun

    Hi u all, sorry for my ignorance but I'm at the very beginning. I adopted the method to write function on a frame in the main timeline since a couple of weeks and if pe. I have 20 mc that onRelease have to open a new window the script become really long.
    mc1.onRelease=function(){
    getURL("imm1.jpg", "_blank");
    }
    mc2.onRelease=function(){
    getURL("imm2.jpg", "_blank");
    }
    ..and so on for 20 times! if then I have to add a rollover and out function for each of them.. mmh..
    there is a way to make all this shorter? I don't know.. a unic function that works for all of them?

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    mc1.onRelease=function(){
    fURL(1);
    }

    mc2.onRelease=function(){
    fURL(2);
    }

    function fURL(num){
    getURL("imm"+num+".jpg", "_blank");
    };

    any help ??

    (or use a for(loop) )

  3. #3
    Member
    Join Date
    May 2006
    Posts
    48
    mmh.. how is working with for(loop)?

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Code:
    for (var i = 1; i<=20; i++) {
    	_root["mc"+i].id = i;
    	_root["mc"+i].onRelease = function() {
    		getURL("imm"+this["id"]+".jpg", "_blank");
    	};
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    Member
    Join Date
    May 2006
    Posts
    48
    thanks a lot!
    can I also add to that script a rollOver and RollOut function?
    because I'm tring and it doesn't work.. it only works when I interact with the mc1(so imm1..) but not mc2 mc3..

  6. #6
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    yw sure u can:

    Code:
    for (var i = 1; i<=20; i++) {
    	
    	//unique identification
    	_root["mc"+i].id = i;
    	
    	//handlers 
    	_root["mc"+i].onRelease = function() {
    		getURL("imm"+this["id"]+".jpg", "_blank");
    	};
    	
    	_root["mc"+i].onRollOver = function() {
    		trace("hello i am movieclip: " + this["id"] + " and u have rolled over me");
    	};
    	
    	_root["mc"+i].onRollOut = function() {
    		trace("hello i am movieclip: " + this["id"] + " and u have rolled out");
    	};
    	
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  7. #7
    Member
    Join Date
    May 2006
    Posts
    48
    that's it
    for (var i = 1; i<=20; i++) {
    _root["mc"+i].id = i;
    _root.win["win"+i]._visible=false;
    _root["mc"+i].onRelease = function() {
    getURL("imm"+this["id"]+".jpg", "_blank");
    };
    _root["mc"+i].onRollOver =function (){
    _root.["win"+i]._visible=true;
    }
    _root["mc"+i].onRollOut =function (){
    _root.["win"+i]._visible=false;
    }
    it works only with the instances named "instance"1

  8. #8
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    u need to use this["id"] to get the correct id. so for e.g

    Code:
    _root["mc"+i].onRollOver =function (){
    _root["win"+this["id"]]._visible=true;
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  9. #9
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    u need to use this["id"] to get the correct id. so for e.g

    Code:
    _root["mc"+i].onRollOver =function (){
    _root["win"+this["id"]]._visible=true;
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  10. #10
    Member
    Join Date
    May 2006
    Posts
    48
    it works only with the number 1..
    I have no idea what's the problem now..

    sorry for the repetition

  11. #11
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    upload your fla ill have a look..im using mx 2004 ..also make sure u added the correct rollout function hence the complete code looks like:

    Code:
    for (var i = 1; i<=20; i++) {
    	
    	//unique identification
    	_root["mc"+i].id = i;
    	
    	//handlers 
    	_root["mc"+i].onRelease = function() {
    		getURL("imm"+this["id"]+".jpg", "_blank");
    	};
    	
    	_root["mc"+i].onRollOver = function() {
    		_root["win"+this["id"]]._visible=true;
    	};
    	
    	_root["mc"+i].onRollOut = function() {
    		_root["win"+this["id"]]._visible=false;
    	};
    	
    }
    Last edited by silentweed; 05-18-2006 at 12:30 PM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  12. #12
    Member
    Join Date
    May 2006
    Posts
    48
    I try to explain me better,
    I have 2 mc on the stage: "tumb" and "win".
    in "tumb" I have "tumb1", "tumb2",.. .."tumb24".
    in "win" I have "win1", "win2",.. .."win24".
    every "win" at the beginning of the movie must be invisible.

    for (var i = 1; i<=25; i++) {

    _root.win["win"+i]._visible=false;
    _root.tumb["tumb"+i].id = i;

    _root.tumb["tumb"+i].onRelease = function() {
    getURL("imm"+this["id"]+".jpg", "_blank");
    }
    _root.tumb["tumb"+i].onRollOver =function (){
    _root.win["win"+this["id"]]._visible=true;
    }
    _root.tumb["tumb"+i].onRollOut =function (){
    _root.win["win"+this["id"]]._visible=false;
    }
    }

    it works only with tumb1 and win1
    please help!!

  13. #13
    Member
    Join Date
    May 2006
    Posts
    48
    sorry, second time you answer and I'm writing..

    here the .fla

    thanks a lot
    Attached Files Attached Files

  14. #14
    Member
    Join Date
    May 2006
    Posts
    48
    did anybody have a look on the file?
    I'm still tring to solve the problem .. but nothing.. please help!

  15. #15
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Hi cant open ur file..try saving it as mx 2004
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  16. #16
    Junior Member
    Join Date
    Oct 2005
    Posts
    26
    I'm looking at your file - but in "win", there's only two MC's, "win1" and "win2". They're all invisible at start.

    Where's the problem?

  17. #17
    Member
    Join Date
    May 2006
    Posts
    48
    but when I roll over the tumb2 win2 should appear, but it doesn't.. only tumb1 and win1 are working..
    I know, at the moment I have only win1 and win2.. they will be 24 anyway.

    the mx2004 here
    Attached Files Attached Files

  18. #18
    Junior Member
    Join Date
    Oct 2005
    Posts
    26
    Okay, I think I found it. The thing is that in the "tumb" MC, only the "tumb1" MC is on frame 1. The others appear in later frames.

    That means that when the script is running at the start of the movie, it can only find "tumb1". The other ones just aren't there yet.

  19. #19
    Member
    Join Date
    May 2006
    Posts
    48
    thak you very very much!

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