Advertisement

06.24.2008 at 02:43AM PDT, ID: 23510356
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

How do I duplicate movie clip and access it?

Asked by NiklasMoller in Macromedia Flash, Miscellaneous Web Development

Tags: , , ,

I have a problem which probably is related to levels or depth in flash, but I just cant work it out...
Basically I have just created a movieclip called "bg_mc". It shows up nicely on my stage, jpg loaded into it and all. so far so good.

I want to duplicate it and then access the new (just duplicated) movieclip. it doesnt work.

I am using the movieClipLoader class to do the loading work for me.
I have assigned some code to a button to find out if the movieclip exists or not.
The duplicated movieclip should exist, but it doesnt (when i press the button, the trace says:  "undefined" when I ask for the ._x position of the duplicated movieclip.)

The dynamic loading of the jpg and the loadMovieClip class function works fine (or so I think... hehe) but the duplicateMovieClip doesnt work... what am I missing here?

Heres my code:
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
function createMovieClipLoaderObject($newObjectName){
	
	//Just store a copy of the name of the object into a new variable:
	var $newObject = $newObjectName;	
	//Convert it to an object:
	var $newObject:MovieClipLoader = new MovieClipLoader();
	
	//create a unique name for this listener:
	var $listener_name = $newObjectName+"_listener";
	//save the new name:
	var $listener = $listener_name;
	//keep the name, but convert it to an object:
	var $listener:Object = new Object();
	
	$listener.onLoadStart = function(target_mc:MovieClip) {
	   trace("*********"+$newObjectName+" instance*********");
	   trace("onLoadStart event triggered:");
	   trace("Your load has begun on movie clip = "+target_mc);
	   var loadProgress:Object = $newObject.getProgress(target_mc);
	   trace(loadProgress.bytesLoaded+" = bytes loaded at start");
	   trace(loadProgress.bytesTotal+" = bytes total at start");
	};
	$listener.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number) {
	   trace("*********"+$newObjectName+" instance Progress*********");
	   trace("onLoadProgress event triggered:");
	   trace("onLoadProgress() called back on movie clip "+target_mc);
	   trace(loadedBytes+" = bytes loaded at progress callback");
	   trace(totalBytes+" = bytes total at progress callback");
	};
	$listener.onLoadComplete = function(target_mc:MovieClip) {
	   trace("*********"+$newObjectName+" instance*********");
	   trace("onLoadComplete event triggered:");
	   trace("Your load is done on movie clip = "+target_mc);
	   var loadProgress:Object = $newObject.getProgress(target_mc);
	   trace(loadProgress.bytesLoaded+" = bytes loaded at end");
	   trace(loadProgress.bytesTotal+" = bytes total at end");
	};
	$listener.onLoadInit = function(target_mc:MovieClip) {
	   trace("*********"+$newObjectName+" instance*********");
	   trace("onLoadInit event triggered:");
	   trace("Movie clip = "+target_mc+" is now initialized");
	   // you can now do any setup required, for example:
	   //trace("width of image is: "+target_mc._width);
	   //trace("height of image is: "+target_mc._height);
	};
	$listener.onLoadError = function(target_mc:MovieClip, errorCode:String) {
	   trace("*********"+$newObjectName+" instance*********");
	   trace("onLoadError event triggered:");
	   trace("ERROR CODE = "+errorCode);
	   trace("Your load failed on movie clip = "+target_mc+"\n"); 
	};
 
	$newObject.addListener($listener);	
 
	return $newObject;
};// end function create object
 
//====================================================================
 
//create new object to handle the loading:
var $my_test = createMovieClipLoaderObject("my_test");
 
//create empty movie clip to use as container for jpg:
_root.createEmptyMovieClip("bg_mc", _root.getNextHighestDepth());
 
// Now load the file into target mc
$my_test.loadClip("tile1.jpg", _root.bg_mc);
 
//when the file is completely loaded, duplicate the mc:
$my_test.onLoadInit = function(target_mc:MovieClip){
	duplicateMovieClip(target_mc, "bg", _root.getNextHighestDepth()); 
	
};//end onLoad init
 
==========================
Actionscript for testing button:
 
testbutton.onRelease = function(){
	trace("duplicate x is: " + _level1.bg._x);
};
[+][-]06.24.2008 at 04:07AM PDT, ID: 21854313

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 05:43AM PDT, ID: 21855017

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 05:51AM PDT, ID: 21855102

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 05:55AM PDT, ID: 21855141

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 05:55AM PDT, ID: 21855147

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 06:04AM PDT, ID: 21855236

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 06:36AM PDT, ID: 21855540

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Macromedia Flash, Miscellaneous Web Development
Tags: Adobe, Flash, 8, Actionscript
Sign Up Now!
Solution Provided By: aneeshchopra
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.24.2008 at 07:43AM PDT, ID: 21856261

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628