PDA

View Full Version : variables containing code


orange gold
06-30-2009, 11:16 AM
well... lets say i have a variable called rop5 (rotation positive 5)
rop5 = _rotation += +5
then i want to say object1.rop5
well obviously this will never work... my just for kicks challenge is to find a similar way to make the following code work!


vas1 = "_" //vas = variable action script... but thats not important :)
vas2 = "r"
vas3 = "o"
vas4 = "t"
vas5 = "a"
vas6 = "i"
vas7 = "n"
vas8 = vas1 + vas2 + vas3 + vas4 + vas5 + vas4 + vas6 + vas3 + vas7
vas9 = "object1." + vas8 + " += +5"
trace(vas9)
_root.onEnterFrame = function() {
vas9
}



HAVE FUN!

dialectric
07-01-2009, 12:29 AM
From another thread, http://www.actionscript.org/forums/showthread.php3?t=180017 , it looks like you could do this with an external interface call.

-dialectric

bowljoman
07-05-2009, 09:11 AM
package {
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;

public class tests extends Sprite
{
[Embed(source='fence.png')]
public var image:Class;
public var obj:Bitmap=new image();

public var rot:String='rotation';
public var someVar:String='obj';

public function tests()
{

addChild(obj);
this.addEventListener(Event.ENTER_FRAME,frame);
}

public function frame(e:Event):void
{
this[someVar][rot]+=1;
}
}
}