SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    0 Post(s)
    0 Thread(s)

    AS3 - Combine Multiple Variable Names Together to Target New Variable


    I'm still learning flash and actionscript 3 and i am having trouble with variable and object names. I need to be able to combine variable names together (in the same way as php can combine by doing var1.var2).

    My swf contains 4 loaders (image1_loader, image2_loader etc..) which are a child of (image1_content, image2_content etc.....)
    I then have 4 buttons which load an image into the loader and while doing so they define the currently active loader.
    Finally i have 4 control buttons - scale up/down and rotate clockwise/anticlockwise which should only control the currently active loader (as set by the buttons above)

    So my buttons as well as loading the image have the event listener:
        image1_btn.addEventListener(MouseEvent.CLICK, setCurrentSelection);
        image2_btn.addEventListener(MouseEvent.CLICK, setCurrentSelection); 
    (and so on..) 
        function setCurrentSelection(e:MouseEvent):void {
    	    if (e.currentTarget===image1_btn){activeLoader='image1';}
    	    if (e.currentTarget===image2_btn){activeLoader='image2';}
    	    if (e.currentTarget===image3_btn){activeLoader='image3';}
    	    if (e.currentTarget===image4_btn){activeLoader='image4';}
    So after setting my activeLoader as the string 'imageX' i have a control functions as in this rotate one:
        rotateClock_btn.addEventListener(MouseEvent.MOUSE_DOWN, rotateClockwise);
        rotateAnti_btn.addEventListener(MouseEvent.MOUSE_DOWN, rotateAntiClockwise);
        function rotateClockwise(event:Event):void {
    	    rotateAroundCenter(imageX_content, 10, ptR);
        function rotateAntiClockwise(event:Event):void {
    	    rotateAroundCenter(imageX_content, -10, ptR);
    So within the rotateClockwise and rotateAntiClockwise functions i need to be able to recognise which is the currently active loader and have that number instead of the X - so if it is image1_loader - it needs to be image1_content, if 4 - image4_content...
    I had tried to do it as this but it doesn't like it being a string:

        rotateAroundCenter((activeLoader+'_content'), 10, ptR);
    Please could anyone help me understand how to solve (sorry if i havent explained it clearly!) and please go easy on me - i'm learning as i go myself


  2. #2
    Community Advisor silver trophy

    Join Date
    Nov 2006
    40 Post(s)
    1 Thread(s)
    It'd be helpful to see the function rotateAroundCenter.

    You could have e.g

    rotateAroundCenter(activeLoader, 10, ptR);

    then inside rotateAroundCenter you could refer to the correct clip using something along the lines of

    var correct_content = MovieClip(getChildByName("activeLoader_"+myIncomingFunctionParameter));

    then perform any operation in the function on correct_content


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts