A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: move movie clips around on y axis

  1. #1
    Senior Member
    Join Date
    Oct 2009
    Posts
    112

    [RESOLVED] move movie clips around on y axis

    have two sets of movie clips.
    I'm communicating to these movie clips with another program via binary sockets.
    For the first set of movie clips: when it recieves its instance name, and a second number (InstanceName+#) from the socket, the named movie clip will jump to the frame corresponding with that number. for ex:
    if the incoming data from the socket is (mc7+3), then movieclip 7 will jump to frame 3.

    For the second set of movie clips: when it recieves its instance name, and a second number (InstanceName+#) from the socket, the named movie clip will move location across the screen, by the y coordinate moving to the # given by the socket...thats a little confusing. for ex:
    if the incoming data from the socket is (mc4+500), then movieclip 4 will move so that it's y coordinate is at 500.

    Here is my code:
    Code:
    var socketBuffer:String = "";
    s.addEventListener(ProgressEvent.SOCKET_DATA, onDATA);
    function onDATA(e:ProgressEvent):void{
      var d:String=s.readUTFBytes(s.bytesAvailable);
      socketBuffer = socketBuffer.concat(d);
      var tokens:Array = socketBuffer.split(".");
      var done:Boolean = false;
      while (tokens.length > 1 && !done){
        var token:String = tokens.shift();
        if (!processToken(token)){
           socketBuffer = token;
           done = true;
        }
      }
      if (!done){
        socketBuffer = tokens.shift();
      }
    }
    
    function processToken(token:String):Boolean{
    	var tempBoolean:Boolean;
            var embeddedNums:Array = token.split('+');
    	if (!embeddedNums  || (embeddedNums.length < 2)){
    		tempBoolean=false;
    	}
    	var clipName:String = embeddedNums[0];
    	var frameIndex:int = Number(embeddedNums[1]);
            if (this[clipName]){
      	  this[clipName].gotoAndStop(frameIndex);
    	  tempBoolean = true;
            }
    		if (this[clipName==FADER.name]){
    		this[clipName].y=(frameIndex);		
    	}
    return tempBoolean;
    }
    i got rid of some errors. the first part is working where the movie clips jump to the frame they are told to so no errors there. but when i try to move the movie clips in reference to the FADER array, (along the y axis) nothing happens. (look at bold part of code) this is pretty confusing so let me know if u need more explanation

    theres also another method i'm willing to approach but i'm not sure how to go about it. rahter than using the FADER array, I would rewrite the code for each individual movie clip, so that it says "if incomign data names a movie clip and gives a number, change the named movie clip's y coordinate to the incoming number"
    Last edited by mattwatts15; 11-20-2009 at 10:24 AM. Reason: change title

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    The way you are referencing things seems really odd. You are declaring clipName in your processToken method , yet you are using array notation to reference what is already scoped to it. Then you enter this conditional,

    if (this[clipName==FADER.name])

    At first look , it seems to me like you should just say

    if( clipName == FADER.name ) //then dosomething

    or if for some reason , you have to use array notation , say

    if( this[ "clipName" ] == FADER.name ) // then dosomething.

    It doesnt appear as though this in a package , or even a class , as i dont see any block declarations , and you are not typing your methods as public , private , etc. Is this just on the timeline , or in an include ?

  3. #3
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    idk about any public class private funcitons etc...(im fairly new to as3), the code here is exactly as it would appear in my flash cs4 actionscript 3 timeline

    you're right, the way I am referencing things is a bit odd because theres a few other functions this code has to do and its a bit complicated...

    i did try the change u suggested but still no luck. no errors, but the movie clips aren't moving to they y-coordinate-location i am requesting...


    is there a way to change "frameIndex" to "frameIndex.valueOf" or "frameIndex.Number"?
    do u know what i mean? like i need to pull out the number of whatever "frameIndex" is, and then send the movie clip's y-coordinate to that number
    let me kno if u have more questions about what im tryin to do

  4. #4
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    well you are already casting it. One thing is you are declaring it as type int , and casting into type Number. I doubt thats your issue , but you really should type the var as a Number. It really should be a numeric value though , and not a string. Without fully understanding what it is you are doing , my best suggestion , if you already havent , would be try tracing out everything. See what values are what. Do a step debug of the whole app. That way you can see line by line , what is what , and what is where.

  5. #5
    Senior Member
    Join Date
    Oct 2009
    Posts
    112

    nearly resolved...

    ok good call. i traced everything and figured out the bits i need, and i figured out something that works:

    Code:
    if (this[clipName]){
    this[clipName].y=(frameIndex);
    only problem is now the movie clips from other arrays are ALSO moving around...i cant remmber if i said it before but the movie clips from other arrays don't move around, but all data is going through the same socket....
    its complicated to explain but basically my question is this:

    is there a way to say something like this?
    Code:
    if (this[clipName].comes from FADERarray){
    this[clipName].y=(frameIndex)
    maybe this[clipName].isPrototypeOf(FADERarray);
    or this[clipName].valueOf(FADERarray);
    i just dont know how all theses bits of code work but i think im close on the principle of it

    thanks!
    Last edited by mattwatts15; 11-20-2009 at 09:11 AM.

  6. #6
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    try this :

    for( var i : int = 0 ; i < FADERarray.length ; i ++ ) {
    if( this[clipName] == FADERarray[ i ] )///you know that i came from fadeArray
    }

    if you dont mind me asking ,why is it that you are using binary sockets ? Is it because the server uses binary ? I always thought binary sockets were only slightly faster then xmlsockets, and were really usefull only when handling , loads and loads of data.
    Last edited by AttackRabbit; 11-20-2009 at 10:06 AM.

  7. #7
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    nothing different happened...
    when i trace FADERarray[i] it would only bring up the first FADER in the array

    you would think then that if clipNAME = the first fader in the array (fader1), that then fader 1 would move, but it didnt

    example: if type in fader30+880. i would expect fader 30's y coordinate to change to 880, but it didnt.
    then when i noticed "i" = fader1, i tried: fader1+880, but sitll nothing happened.

    i traced clipName.concat(FADERarray), and it came up with a list of all faders in the array (rather than just the first), so i tried that in the code but for some reason it's still not working. can't figure out why

  8. #8
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    this worked tho!
    if (FADERarray.indexOf(clipName) != -1){
    this[clipName].y = frameIndex;
    }

  9. #9
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    good to hear. Honestly , and no offense , you might at least consider going back later , once you get this whole thing working , and re-factor the code. I think a lot of the trouble you are having is due to improper typing and referencing. I think you are making this a little more complicated then it needs to be. Again just a suggestion , no disrespect intended.

  10. #10
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    yea i agree its complicated but this code has do do a load of other functions as well, and that main confusing chunk of code is filtering all incoming data through only 1 binary socket, which is why it has so many different variables, for now at my level of as3 understanding i think this is about as simple as it will get...this code has already been simplified from about 8 layers/8pages of code, to one Socket function, and all objects on one layer

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center