Copy link to clipboard
Copied
Hi All,
I am not able to create a empty movie clip inside a empty movieClip.
Here the code..
var photoHolder:MovieClip=new MovieClip();
addChild(photoHolder);
var photo:MovieClip=new MovieClip();
photoHolder.addChild(photo);
trace(photoHolder.photo.x)
// the message i got is ---------------------------------
TypeError: Error #1010: A term is undefined and has no properties.
at Untitled_fla::MainTimeline/frame1()
//------------------------------------------------------------------
Can you correct my code if i am wrong !!!
Thanks,
Karthic
When you create objects dynamically you can no longer use the dot method to target objects like you can when you manually create them. To target the dynamically created child of photoHolder you need to use indirect targeting methods such as photoHolder.getChildByName("photo") or photoHolder.getChildAt(0), etc... but you don't need to go that route anyways because...
You already have a direct route to target photo (as in, photo), so you don't need to target it via photoHolder.
Copy link to clipboard
Copied
I Think why don't you use trace(photo.x). I am expecting the x position will be zero
Copy link to clipboard
Copied
if you use "trace(photo.x)" that means the movieclip "photo" is on stage, not inside "photoHolder" Movieclip,
I think, you got it !!!
Copy link to clipboard
Copied
photo is inside photoHolder, but as I said, you cannot target it like you normally would (and you don't have to). YOu can test that it is by checking the value of.... trace(photo.parent);
Copy link to clipboard
Copied
When you create objects dynamically you can no longer use the dot method to target objects like you can when you manually create them. To target the dynamically created child of photoHolder you need to use indirect targeting methods such as photoHolder.getChildByName("photo") or photoHolder.getChildAt(0), etc... but you don't need to go that route anyways because...
You already have a direct route to target photo (as in, photo), so you don't need to target it via photoHolder.
Copy link to clipboard
Copied
Ned Murphy, You rocks !!!, superb !!!
Thankyou !!!
Copy link to clipboard
Copied
I should clarify that if you use the getChildByName() method, you need to have assigned a name property to the object. The variable name "photo" is not its name property. YOu have to specifically assign the name property, as in... photo.name = "whatever"; such that in the method you would then use...
photoHolder.getChildByName("whatever")
Copy link to clipboard
Copied
Yeah Ned Murphy, I was using this getchildbyName() and getChildAt() methods, last 6 month i didn't work on flash, When i ask this question i totally fotgot every think. After seeing you comment i got everythink back and i done the flash,
Here 2 way to access photo inside photoholder !!!
---------------------------------------------------------------------------------------------------------------------
import flash.display.MovieClip;
var photoHolder:MovieClip = new MovieClip();
var photo:MovieClip = new MovieClip();
photo.name = "photo";
addChild(photoHolder);
photoHolder.addChild(photo);
var method_1:MovieClip = photoHolder.getChildByName("photo") as MovieClip;
trace(method_1.x);
//or
var method_2:MovieClip = photoHolder.getChildAt(0) as MovieClip;
trace(method_2.x);
---------------------------------------------------------------------------------------------------------------------
this is working fine,
can you tellme is this right way ?
Copy link to clipboard
Copied
Yes, both of those are legitimate to use, but don't forget that if you have photo declared, you can target it directly and don't need to do so indirectly, as in...
trace(photo.x);
If you have many photos to include in the holder, then you could assign them to an array and still target them directly using the array, though you need to keep track of the index values for individual photos.
Copy link to clipboard
Copied
Ok, can you explain bit more about using array !!!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more