I can get this to work on attachMovie but it won’t work in this case.
_root.createEmptyMovieClip("temper", 1,{_x:60, _y:40});
trace(temper._x);
What am I missing?
I can get this to work on attachMovie but it won’t work in this case.
_root.createEmptyMovieClip("temper", 1,{_x:60, _y:40});
trace(temper._x);
What am I missing?
You are not missing anything… You are adding more argument in there though…
myMovieClip.createEmptyMovieClip (instanceName, depth)
Yes I am aware of that but I was using the object literal as I have seen it been used and was interested in seeing how it worked. As I said I used the same set up in attachMovie and it worked.
_root.attachMovie("temper","temp",2,{_x:200,_y:70});
trace(temp._x);
The trace shows 200
This works now I have seen the same object literal use in the
_root.createEmptyMovieClip("test",3,{_x:40,_y:200});
trace(test._x);
trace here shows 0
IS this more clear
And why can"t it be done on the creatEmptyMovieClip
I have seen it been used
Are you saying that somebody used that initialization object with the createEmptyMovieClip() function or attachMovie() function???
Yes, you can use that with attachMovie() function since Macromedia gave us a room to use with, but not with the createEmptyMovieClip() function… createEmptyMovieClip() function just takes two arguments… No more than that unless there is some sort of undocumented function somewhere… (You could create the prototype that takes object literal though, but I don’t think that will be so useful though…) Check out the ActionScript dictionary and compare two functions side by side…
I am checking into right now.
your probably right
it can’t be used but I saw someone use it but I didn’t check to see if it worked for them.
Thanks for your replies
You’re welcome… Please let me know after you checking it out…
No your right it does not work for createEmptyMovieClip. I checked everything
Thanks for your help on this.
No problem… Drop by anytime…
yeah I thought it was pretty recokulous not to include that option for createEmptyMovieClip. You can make your own version to do that though.
MovieClip.prototype.$createEmptyMovieClip = MovieClip.prototype.createEmptyMovieClip;
MovieClip.prototype.createEmptyMovieClip = function(name, depth, init){
var mc = this.$createEmptyMovieClip(name, depth);
init.__proto__ = null;
for (var prop in init) mc[prop] = init[prop];
return mc;
}
just throw that in the first frame of your movie to immediately initialize it, then you can use createEmptyMovieClip with an init object just like attachMovie
Nice one, senocular…
cool can you explain it a little. I love when people give you these things but I always have to know how it was built and what each line does.
If you can take the time to do that it would be super cool
also I have never seen this been used
$createEmptyMovieClip
the $ sign that is before the function.
$ is just another character that can be used in variable names. What Im doing with
MovieClip.prototype.$createEmptyMovieClip = MovieClip.prototype.createEmptyMovieClip;
is just saving the original createEmptyMovieClip into a new variable called $createEmptyMovieClip. I didnt have to use $createEmptyMovieClip, I could have just as well said bob, but I need to use the original createEmptyMovieClip in my new function so I have to save it. I cant just use createEmptyMovieClip because the new function Im making IS createEmptyMovieClip so calling createEmptyMovieClip within itself would be calling itself and would cause an infinite recursion loop. The $ is seen with PHP and other languages of the such which makes it comfortable for those kinds of programmers to use Flash - but its common to use it in situations like this in renaming a pre-existing function or setting up something thats tied into a system event or something… but its nothing set in stone.
createEmptyMovieClip is kept within the movieclip prototype object which is an object that holds functions and variables for all movieclips. So any movieclip has access to using createEmptyMovieClip as long as its in the MovieClip.prototype. You can just as well make your own prototypes for MovieClips or other objects like Array and String etc. See http://proto.layer51.com for more.
MovieClip.prototype.createEmptyMovieClip = function(name, depth, init){
defines our new re-write of createEmptyMovieClip for the MovieClip.prototype and allows 3 arguments; the original name and depth and the new init argument which is an initiation object as seen with attachMovie.
var mc = this.$createEmptyMovieClip(name, depth);
here a new movieclip, mc, is created using the saved $createEmptyMovieClip which is the original createEmptyMovieClip function.
init.__proto__ = null;
This takes away the prototype reference from the init object. Without this, since the init object IS an object, the following for in loop will not only cycle through the properties you specified in it, but also all the properties within the Object.prototype, which, like the MovieClip.prototype, holds functions and variables which are cosistent with all Objects. We dont want those to be set for the movieclip being created, just the ones manually specified in the actual init object. The proto property tells the object where to find its Object.prototype. Setting the proto of the init object to null means that it looks at null to find all of its common properties and functions. This way the inti object no longer references the Object.prototype to look for common properties of the such… instead it looks at null, and of course theres nothing there
for (var prop in init) mc[prop] = init[prop];
The for in loop loops through a specified object going through all its properties/variables/functions. This includes the prototype functions (which arent explicitly hidden) which is why we needed the previous line. Here we are cycling through the init object and all the properties within it. For each loop, the current property is assigned to the prop variable. This is then used to set (or assign) that variable in the movieclip created, mc, to the value it has in the init object using associative array referencing. For more on that see
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=12082
After that, the mc is returned with
return mc;
and the world is a happier place
Cool thanks so much
Most people wont spend the time doing this because half them just copy it from someone else and don’t even know the answers themselves.
I am going to study this now thanks again.
Great explanation, senocular…
As one of those people who just copies other people’s good stuff, I really appreciate the explanation… :beam:
Your explanation made me remember one thing that I have read a while ago… It was about the usage of proto in FMX… This is the paragraph from the ActionScript Coding Standards…
Object Inheritance
Setting the “proto” property to create inheritance was the practice with Macromedia Flash Player 5. This practice is unsupported in Macromedia Flash Player 6 and is not recommended. proto should be treated as a read-only property. The correct way to do accomplish inheritance is to create a prototype chain. To create a prototype chain, set the “prototype” property of the subclass constructor function to an instance of the superclass using the following syntax:
ChildClass.prototype = new ParentClass();
**An example of this practice: **
function Shape()
{
}
function Rectangle()
{
}
Rectangle.prototype = new Shape();
**The following practice is NOT recommended: **
*Rectangle.prototype.proto = Shape.prototype; *
If developers are concerned that this form of inheritance will lead to all of the constructor code being called unnecessarily, the following code can prevent this:
_global.SuperClassConstructor = function() {
if (this._name!=undefined) {
// real constructor code goes here
}
}
In the above code, the constructor code will not execute because there is no instance defined yet. Note that this code only works with Movie Clip-based classes.
Why am I quoting all this??? I just want to hear your opinion on this…
Can this thing similar to random() and Math.random()??? Lots of people use random() no matter what, and we are not experiencing any problem yet… Or is it something more significant than random()???
Appreicate your great explanation again… :beam:
Senocular: I hate you.
::runs away jealous::
How did you know that is the exact feeling that I have on him??? :beam:
Because, hes too good… I think most people here have that feeling of him. At least he shares his knowledge, that rocks!
Yup… That’s why I like him… :beam:
:!: I didnt know proto was “unsupported” in 6. I know its not standard or really recomended to use it, but I was hoping it’d be around for a while because its really nice to have… this example being a good … example of how it can easily solve that problem.
As for my take on it, if it works, Ill use it. I use random now because its less typing and its faster than Math.random(). proto I dont use often, and typically use the ‘correct’ MM method for inheritance, but for things like this, I find it to be the best, quickest solution for removing and prototype references. Actually… hmmm Ive never tried to do it without using proto … I wonder how it would be done then :thinks:
Dont hate me because Im beautiful :flower:
:: Copyright KIRUPA 2024 //--