A Flash Developer Resource Site

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

Thread: No multiple loadEvent.currentTarget.content in function?

  1. #1
    Junior Member
    Join Date
    Aug 2005
    Posts
    27

    No multiple loadEvent.currentTarget.content in function?

    Just as the title says, it will only execute the last one.

    Code:
    function salesMarketing(loadEvent:Event){
    	hold4_MC.addChild(loadEvent.currentTarget.content);
    	hold5_MC.addChild(loadEvent.currentTarget.content);
    	hold6_MC.addChild(loadEvent.currentTarget.content);
    	hold7_MC.addChild(loadEvent.currentTarget.content);
    }

  2. #2
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Code:
    function salesMarketing(loadEvent:Event){
    	
    	var loadedContent:MovieClip = new MovieClip();
    	loadedContent = loadEvent.currentTarget.content;
    	loadedContent2 = loadEvent.currentTarget.content;
    	loadedContent3 = loadEvent.currentTarget.content;
    	loadedContent4 = loadEvent.currentTarget.content;	
    
    	hold4_MC.addChild(loadedContent);
    	hold5_MC.addChild(loadedContent2);
    	hold6_MC.addChild(loadedContent3);
    	hold7_MC.addChild(loadedContent4);
    }
    Try that and lemme know if that works.
    Last edited by Beathoven; 04-28-2009 at 06:15 PM.

  3. #3
    Junior Member
    Join Date
    Aug 2005
    Posts
    27
    1120: Access of undefined property loadedContent.

  4. #4
    Junior Member
    Join Date
    Aug 2005
    Posts
    27
    Wait forgot the other line. It does the same thing.

  5. #5
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Try this:

    Code:
    function salesMarketing(loadEvent:Event){
    	
    	var loadedContent:MovieClip = new MovieClip();
    	var loadedContent2:MovieClip = new MovieClip();
    	var loadedContent3:MovieClip = new MovieClip();
    	var loadedContent4:MovieClip = new MovieClip();
    	loadedContent = loadEvent.currentTarget.content;
    	loadedContent2 = loadEvent.currentTarget.content;
    	loadedContent3 = loadEvent.currentTarget.content;
    	loadedContent4 = loadEvent.currentTarget.content;	
    
    	hold4_MC.addChild(loadedContent);
    	hold5_MC.addChild(loadedContent2);
    	hold6_MC.addChild(loadedContent3);
    	hold7_MC.addChild(loadedContent4);
    }

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    A single DisplayObject can only be on the displayList in one place. It does not matter how many variables you have referring to that object, it will only show up once.

  7. #7
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Quote Originally Posted by 5TonsOfFlax View Post
    A single DisplayObject can only be on the displayList in one place. It does not matter how many variables you have referring to that object, it will only show up once.
    Could you clone it somehow?

  8. #8
    Member
    Join Date
    Feb 2001
    Posts
    56
    Senocular came up with some cloning code that seems to get around this issue.

    duplicateDisplayObject.as

    It worked in several instances for me - and mucho kudos to Senocular for coming up with it.

    -<>|TheMadFlasher|<>-

  9. #9
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    So how would one use that class?

    import it and then, for the matter at hand here:

    Code:
    hold4_MC.addChild(duplicateDisplayObject(loadEvent.currentTarget.content, false));
    or what?
    Last edited by Beathoven; 04-28-2009 at 06:50 PM.

  10. #10
    Member
    Join Date
    Feb 2001
    Posts
    56

    Arrow

    He's written it as a function - just copy the function itself in your code add the imports...

    PHP Code:
    // imports to ad
    import flash.display.DisplayObject;
    import flash.geom.Rectangle;
    import flash.system.Capabilities;

    // placed in your "salesMarketing" function
    var dupDO:DisplayObject;
    var 
    numDups:int 4;

    for (var 
    n:int 0numDupsn++){
        
    dupDO duplicateDisplayObject(loadEvent.currentTarget.contentfalse);
        
    addChild(dupDO);

    And then buy Senocular a beer when you meet him because you used his code ...

    -<<|thEmAdFlasHer|<>-

  11. #11
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Nice. Thanks for that!

  12. #12
    Junior Member
    Join Date
    Aug 2005
    Posts
    27
    So like this? If so this is not working.

    PHP Code:
    function salesMarketing(loadEvent:Event){


        
        var 
    dupDO:DisplayObject;
    var 
    numDups:int 4;

    for (var 
    n:int 0numDupsn++){
        
    dupDO duplicateDisplayObject(loadEvent.currentTarget.contentfalse);
        
        
    hold4_MC.addChild(dupDO);
        
    hold5_MC.addChild(dupDO);
        
    hold6_MC.addChild(dupDO);
        
    hold7_MC.addChild(dupDO);

        



    Gave me this error: 1180: Call to a possibly undefined method duplicateDisplayObject.

    So I assume it cant find the duplicateDisplayObject function so I pasted in the whole function from Senocular, no error but it crashed flash when I clicked the button that calls salesMarketing function. Any ideas? What am I doing wrong.
    Last edited by aemciv; 04-29-2009 at 10:15 AM.

  13. #13
    Junior Member
    Join Date
    Aug 2005
    Posts
    27
    Any insight MadFlasher/Beathoven? I am about ready to switch this to AS2!

  14. #14
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    In the last code you posted, you are still adding the same displayobject to multiple containers. That still doesn't work. It will continue to not work. Add a new duplicate to each place you want it to show up.

    PHP Code:
    function salesMarketing(loadEvent:Event){
        
    hold4_MC.addChild(duplicateDisplayObject(loadEvent.currentTarget.contentfalse));
        
    hold5_MC.addChild(duplicateDisplayObject(loadEvent.currentTarget.contentfalse));
        
    hold6_MC.addChild(duplicateDisplayObject(loadEvent.currentTarget.contentfalse));
        
    hold7_MC.addChild(duplicateDisplayObject(loadEvent.currentTarget.contentfalse));

    As for the undefined method error, you most likely copied it into the wrong place. It should be in the same context as the code above.

  15. #15
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    EDIT: nevermind.

  16. #16
    Junior Member
    Join Date
    Aug 2005
    Posts
    27
    Okay, here is my code, is this correct? When I call the salesMarketing function flash crashes. what the heck?

    Code:
    import flash.display.DisplayObject;
    import flash.geom.Rectangle;
    import flash.system.Capabilities; 
    
    
    function duplicateDisplayObject(target:DisplayObject, autoAdd:Boolean = false):DisplayObject {
    		var targetClass:Class = Object(target).constructor;
    		var duplicate:DisplayObject = new targetClass() as DisplayObject;
    		
    		// duplicate properties
    		duplicate.transform = target.transform;
    		duplicate.filters = target.filters;
    		duplicate.cacheAsBitmap = target.cacheAsBitmap;
    		duplicate.opaqueBackground = target.opaqueBackground;
    		if (target.scale9Grid) {
    			var rect:Rectangle = target.scale9Grid;
    			
    			if (Capabilities.version.split(" ")[1] == "9,0,16,0"){
    				// Flash 9 bug where returned scale9Grid as twips
    				rect.x /= 20, rect.y /= 20, rect.width /= 20, rect.height /= 20;
    			}
    			
    			duplicate.scale9Grid = rect;
    		}
    		
    		// add to target parent's display list
    		// if autoAdd was provided as true
    		if (autoAdd && target.parent) {
    			target.parent.addChild(duplicate);
    		}
    		return duplicate;
    	}
    
    
    function salesMarketing(loadEvent:Event){
        
    	hold4_MC.addChild(duplicateDisplayObject(loadEvent.currentTarget.content, false));
    	hold5_MC.addChild(duplicateDisplayObject(loadEvent.currentTarget.content, false));
    	hold6_MC.addChild(duplicateDisplayObject(loadEvent.currentTarget.content, false));
    	hold7_MC.addChild(duplicateDisplayObject(loadEvent.currentTarget.content, false));
    
    }

  17. #17
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The code doesn't look terribly wrong. What do you mean by crash? Does the Flash IDE completely die, or do you get some error message?

    If it's the former, your fla may have become corrupt. I don't trust the flash IDE at all.

    Also, that duplicateDisplayObject function assumes that the object to be cloned has a no-argument constructor (if it's a plain Sprite or MovieClip, that's fine), it also does not set any properties that may have been changed.

  18. #18
    Junior Member
    Join Date
    Aug 2005
    Posts
    27
    Flash as software crashes and I have to relaunch.

  19. #19
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Yeah, it shouldn't do that. There should be no way to crash flash by entering bad actionscript. Unfortunately, that is not the case.

    I hope you've got a backup of your fla from earlier.

  20. #20
    Junior Member
    Join Date
    Aug 2005
    Posts
    27
    it is only if I click the button that calls that script. If I take it out it does not crash, so it has to be the AS, no?

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