So, I’m kinda trying to just play around with actionscript and animations so I ended up by making a small “game” of somekind.
And what I have created now is that you’re able to throw objects (some sort of knives or something).
However, to get a some smooth gravitation and so, I want to have the code inside a onClipEvent(enterFrame) inside the movieclip.
I have created a movieclip with the code inside (how It shall move and so on) but I dont want it to be on the scene at the start (or actully, not before I “summon” it) and if I delete it from the scene, it apperas that the code inside it disapperas when I remove it.
So the now for the questions:
How can I (if possible) create a movieclip with a actionscript assigned to it?
So, I’m kinda trying to just play around with actionscript and animations so I ended up by making a small “game” of somekind.
And what I have created now is that you’re able to throw objects (some sort of knives or something).
However, to get a some smooth gravitation and so, I want to have the code inside a onClipEvent(enterFrame) inside the movieclip.
I have created a movieclip with the code inside (how It shall move and so on) but I dont want it to be on the scene at the start (or actully, not before I “summon” it) and if I delete it from the scene, it apperas that the code inside it disapperas when I remove it.
So the now for the questions:
How can I (if possible) create a movieclip with a actionscript assigned to it?
Cheers
// Klorixx[/quote]
Ok, first of all, if you don’t want it at the start just place it in a different frame. If not read up and look up attachMovie(), which will attach an MC from your library.
When attaching MC’s you can’t assign it AS by onClipEvent(), what you will do is something like:
myMc.onEnterFrame = function(){
//all your code here.
}
were myMc is the linkage name of your MC in the library. Read around and check out Kirupa’s tutorials.
you dont need onLoad, just remove it and have it right on the stage.
like;
[AS]
var weapon:String = “lemon”;
var weapon_counter:Number = 0;
var weapon_speed:Number = 8;
var weapon_y_speed:Number = 0;
var weapon_y_power:Number = 8;
var old_weapon_speed:Number = weapon_speed;
var weapon_rotation:Number = 30;
var old_weapon_rotation:Number = weapon_rotation;
_root.weapon._x = _root.char._x+weapon_speed;
_root.weapon._y = _root.char._y+1;
this._xscale = _root.char._xscale;
this._yscale = _root.char._xscale;
_root.status_box.status_field2.text = _root.weapon._x;
[/AS]
[quote=Macsy;2334356]it will be loaded onto the stage.
but you should do like this:
ActionScript Code:
[LEFT][COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]attachMovie[/COLOR]COLOR=#000000[/COLOR];
wpn.[COLOR=#000080]weapon[/COLOR]:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“lemon”[/COLOR];
wpn.[COLOR=#000080]weapon_counter[/COLOR]:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]0[/COLOR];
wpn.[COLOR=#000080]weapon_speed[/COLOR]:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]8[/COLOR];
wpn.[COLOR=#000080]weapon_y_speed[/COLOR]:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]0[/COLOR];
wpn.[COLOR=#000080]weapon_y_power[/COLOR]:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]8[/COLOR];
wpn.[COLOR=#000080]old_weapon_speed[/COLOR]:[COLOR=#0000FF]Number[/COLOR] = weapon_speed;
wpn.[COLOR=#000080]weapon_rotation[/COLOR]:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]30[/COLOR];
wpn.[COLOR=#000080]old_weapon_rotation[/COLOR]:[COLOR=#0000FF]Number[/COLOR] = weapon_rotation;
wpn.[COLOR=#0000FF]_x[/COLOR] = [COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]char[/COLOR].[COLOR=#0000FF]_x[/COLOR]+weapon_speed;
wpn.[COLOR=#0000FF]_y[/COLOR] = [COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]char[/COLOR].[COLOR=#0000FF]_y[/COLOR]+[COLOR=#000080]1[/COLOR];
[COLOR=#808080]//I assume This is wpn[/COLOR]
wpn.[COLOR=#0000FF]_xscale[/COLOR] = [COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]char[/COLOR].[COLOR=#0000FF]_xscale[/COLOR];
wpn.[COLOR=#0000FF]_yscale[/COLOR] = [COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]char[/COLOR].[COLOR=#0000FF]_xscale[/COLOR];
[COLOR=#0000FF]for[/COLOR][COLOR=#000000]([/COLOR]i [COLOR=#0000FF]in[/COLOR] wpn[COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]trace[/COLOR]COLOR=#000000[/COLOR]
[COLOR=#000000]}[/COLOR]
status_box.[COLOR=#000080]status_field2[/COLOR].[COLOR=#0000FF]text[/COLOR] = [COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]weapon[/COLOR].[COLOR=#0000FF]_x[/COLOR];
[/LEFT]
so every var will become in the attached mc called wpn. the for loop just traces all the loaded vars.
is this what you wanted? I assume that this is loaded in root. correct?
you cant use onLoad for that.
This works![/quote]
Tried your code, but all I get is a Syntax error on the “wpn.weapon:String = “lemon”;”.
However it seems that the problem is on the line:
"this.attachMovie(“weapon”,“wpn”,this.getNextHighestDepth());"
I tried change this to _root since I want to be on the root and not inside my char movieclip (maybe does atter, but this code is loaded inside a movieclip).
My only problem now is that the onEnterFrame function doesn’t appear to loop, therefor the object won’t move.
Anyone can point out what I did wrong here?