-
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);
}
-
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.
-
1120: Access of undefined property loadedContent.
-
Wait forgot the other line. It does the same thing.
-
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);
}
-
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.
-
Originally Posted by 5TonsOfFlax
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?
-
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|<>-
-
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.
-
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 = 0; n < numDups; n++){
dupDO = duplicateDisplayObject(loadEvent.currentTarget.content, false);
addChild(dupDO);
}
And then buy Senocular a beer when you meet him because you used his code ...
-<<|thEmAdFlasHer|<>-
-
-
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 = 0; n < numDups; n++){ dupDO = duplicateDisplayObject(loadEvent.currentTarget.content, false); 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.
-
Any insight MadFlasher/Beathoven? I am about ready to switch this to AS2!
-
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.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)); }
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.
-
-
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));
}
-
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.
-
Flash as software crashes and I have to relaunch.
-
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|