A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Componet coding issues

  1. #1
    Junior Member
    Join Date
    Aug 2006
    Posts
    15

    Exclamation Componet coding issues

    I need help with the code for a component. I am trying to change the rotation from being any key to assigning it as to a specific key. Here's the code:

    #initclip
    function drag() {
    // recive the instance name from drag&drop on stage
    var target = this._parent[this._targetInstanceName];
    var temp = this.ang;
    // cursor changing to hand
    target.useHandCursor = this.showHand;
    target.snapToCenter = this.snapToCenter;
    // keyboard listener definition
    // mouse pressed action
    keyboard = new Object();
    target.onPress = function() {
    // getting the object rotation
    rot = target._rotation;
    // keyboard rotation action
    keyboard.onKeyDown = function() {
    rot = rot+temp;
    target._rotation = rot;
    };
    Key.addListener(keyboard);
    // drag action
    this.startDrag(this.snapToCenter);
    };
    // smoother move
    target.onmousemove = function() {
    updateAfterEvent();
    };
    target.onmouseup = function() {
    this.stopDrag();
    Key.removeListener(keyboard);
    };
    // hide component icon
    setProperty(this, _visible, false);
    }
    // rigister
    Object.registerClass("dragandrotate", drag);
    #endinitclip

    Here's the code I have for each key:

    if(Key.getCode()==Key.LEFT){
    this._mc._rotation++;}
    if(Key.getCode()==Key.RIGHT){
    this._mc._rotation--;}

    Let me know if you can help. Thanks

  2. #2
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    Change this:

    Code:
    // keyboard rotation action
    keyboard.onKeyDown = function() {
    rot = rot+temp;
    target._rotation = rot;
    };
    Key.addListener(keyboard);
    To:

    Code:
    keyboard.target=this;
    // keyboard rotation action
    keyboard.onKeyDown = function()
    {
        if(Key.getCode() == Key.LEFT)
        {
            this.target._parent[this.target._targetInstanceName]._rotation+=this.target.ang
        }
        else
        {
            this.target._parent[this.target._targetInstanceName]._rotation-=this.target.ang
        }
    };
    Key.addListener(keyboard);

  3. #3
    Junior Member
    Join Date
    Aug 2006
    Posts
    15
    Do I do the exact same for going right for example:
    if(Key.getCode() == Key.RIGHT)

    Do I change that for the right key?

  4. #4
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    Sorry, change the following from the code i posted above:

    Code:
    if(Key.getCode() == Key.LEFT)
        {
            this.target._parent[this.target._targetInstanceName]._rotation+=this.target.ang
        }
        else
        {
            this.target._parent[this.target._targetInstanceName]._rotation-=this.target.ang
        }
    To:

    Code:
    if(Key.getCode() == Key.LEFT)
        {
            this.target._parent[this.target._targetInstanceName]._rotation+=this.target.ang
        }
        else if(Key.getCode() == Key.RIGHT)
        {
            this.target._parent[this.target._targetInstanceName]._rotation-=this.target.ang
        }

  5. #5
    Junior Member
    Join Date
    Aug 2006
    Posts
    15
    Hey, I entered the last code you sent me into the component. I then attached the component to the movie clip and wouldn't rotate at all. If it isn't too much trouble, could you send me the complete code for the component because I might of entered it incorrectly or something. Thanks a lot.

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