• creating a method at run time. possible? as2
    17 replies, posted
so i was wondering if it was at all possible to dynamicly create a method or function in as2 at run-time or possibly create and compile as2 code from as2 classes, then use it in the app it was used? or something that has similar effects? can please to helping me?
From my knowledge you cannot. What is your goal? There is probably another way to do it.
I'm trying to make buttons and make them all have different functions on creation. (there made with obj.attachMovie() run from a method.) I'm sure there is but I'm picky. might just sudo quit
you could make a set of functions and attach one to each button, not sure how thats done but i think it's possible
Since AS is a derivative of ECMAScript, you [b]may[/b] be able to create a new Function object
Oh i get it, after you create the button use this: [code]button.onPress = function() { gotoAndStop("menu"); // just any code here }[/code] (you can use any function call, for example you can also have the button run code every frame: [code]button.onEnterFrame = function() { }[/code] )
eval() a function definition..?
[QUOTE=Naelstrom;26583717]Oh i get it, after you create the button use this: [code]button.onPress = function() { gotoAndStop("menu"); // just any code here }[/code] (you can use any function call, for example you can also have the button run code every frame: [code]button.onEnterFrame = function() { }[/code] )[/QUOTE] this looks good. but how would i make it so that the actual code in the function is changable. so if i created a button, i could then make it do different stuff, depending on the, for example instance name.
lua is much better than as2 or whatever that is [highlight](User was permabanned for this post ("Gimmick" - PLing))[/highlight]
[QUOTE=Tweep;26642160]lua is much better than as2 or whatever that is[/QUOTE] please dont bitch about bullshit. it doesn't help anyone to be a shit head. did you think that just maybe I'm using as2 cause I'm getting payed or its for a course? don't be a douche and just help. if you are not at all able to help with your shit filled, pea sized brain, just fuck off.
[QUOTE=ACCE69;26642340]please dont bitch about bullshit. it doesn't help anyone to be a shit head. did you think that just maybe I'm using as2 cause I'm getting payed or its for a course? don't be a douche and just help. if you are at all able to with your shit filled, pea sized brain. or just fuck off.[/QUOTE] He's just a bad troll/spammer. Just report and ignore.
by the way, Justin Bieber is a faggot and only 12 years old... not something to be proud of... just so you know (fag) go rape a shit. [editline]12th December 2010[/editline] [QUOTE=st0rmforce;26642360]He's just a bad troll/spammer. Just report and ignore.[/QUOTE] good point. i just hate it when people cant help, so they say something is shit. no matter how true it might be.
[QUOTE=ACCE69;26642372]by the way, Justin Bieber is a faggot and only 12 years old... not something to be proud of... just so you know (fag) go rape a shit. [editline]12th December 2010[/editline] good point. i just hate it when people cant help, so they say something is shit. no matter how true it might be.[/QUOTE] your right i cant help because i dont do as2. i do lua. and im not saying its shit BECAUSE i cant help. its because it is shit.
[QUOTE]no matter how true it might be.[/QUOTE] i don't care it defeats the purpose of asking for help on AS2! if your talking about lua.
to dynamically access instance names, you need to put them in brackets. For example if you created a button on stage named "button35" you can call it like this: [code]i = 35; _root["button"+i].onPress = function() { //what happens when this button is pressed }[/code]
[QUOTE=Naelstrom;26648888]to dynamically access instance names, you need to put them in brackets. For example if you created a button on stage named "button35" you can call it like this: [code]i = 35; _root["button"+i].onPress = function() { //what happens when this button is pressed }[/code][/QUOTE] how would i make this bit dynamic?"//what happens when this button is pressed" could i do it like [code] var i = 69; function example1 (){ trace("something"); } function example2(){ trace("something else"); } _root["button"+i].onPress = example1(); _root["button"+i+1].onPress = example2(); [/code] ?
yes. that would make it so when you press button69 it'll trace "something" and when you press button691 it'll trace "something else"
[QUOTE=Naelstrom;26721399]yes. that would make it so when you press button69 it'll trace "something" and when you press button691 it'll trace "something else"[/QUOTE] freaking O for Orsome guys. works a charm. Edit: works if... [code]function test(){ trace("test"); } _root["button"+i].onPress = test();[/code] this works a charm.
Sorry, you need to Log In to post a reply to this thread.