dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Problem with as2 to as3

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    1

    Problem with as2 to as3

    AS2

    Code:
    drag_mc.onPress = function() {
    	this._parent.chkDrag();
    	this._parent.oldXmouse = _root._xmouse;
    };
    drag_mc.onRelease = function() {
    	delete drag_mc.onEnterFrame;
    };
    drag_mc.onReleaseOutside = drag_mc.onRelease;
    
    function chkDrag() {
    	drag_mc.onEnterFrame = function() {
    		//trace(111);
    		//trace("xxx="+this._parent.oldXmouse);
    		//trace("yyy="+_root._xmouse);
    		if (this._parent.oldXmouse == _root._xmouse) {
    			trace("==");
    
    		} else if (this._parent.oldXmouse<_root._xmouse) {
    			this._parent.mcNext();
    		} else if (this._parent.oldXmouse>_root._xmouse) {
    			this._parent.mcBack();
    		}
    
    		this._parent.oldXmouse = _root._xmouse;
    
    
    	};
    }
    
    function mcNext() {
    	trace(">>");
    	if (_mc._currentframe+3>_mc._totalframes) {
    		_mc.gotoAndStop(1);
    	} else {
    		_mc.gotoAndStop(_mc._currentframe+1);
    	}
    }
    function mcBack() {
    	trace("<<");
    	if (_mc._currentframe-3<1) {
    		_mc.gotoAndStop(_mc._totalframes);
    	} else {
    		_mc.gotoAndStop(_mc._currentframe-1);
    	}
    }
    In AS3 , i try but it doesnt work. T T

    Code:
    drag_mc.buttonMode = true; 
    
    var oldXmouse:Number = new Number();
    drag_mc.addEventListener(MouseEvent.MOUSE_DOWN, chkDrag);
    drag_mc.addEventListener(MouseEvent.MOUSE_UP, remove);
    
    function remove(event:MouseEvent): void{
    		drag_mc.removeEventListener(Event.ENTER_FRAME,ent);
    }
    
    
    function chkDrag(event:MouseEvent): void{
    
    	var oldXmouse:Number = MovieClip(root).mouseX;
    	
    	drag_mc.addEventListener(Event.ENTER_FRAME, ent);
    	
    }
    		function ent(event:Event): void{
    			
    			if (oldXmouse == MovieClip(root).mouseX){
    			trace("==");}
    			else if  (oldXmouse<MovieClip(root).mouseX){
    				
    				drag_mc.addEventListener(Event.ENTER_FRAME, mcNext); 
    			
    			}
    			else if  (oldXmouse>MovieClip(root).mouseX){
    				
    				drag_mc.addEventListener(Event.ENTER_FRAME, mcBack);
    				
    			}	
    	
    }
    
    function mcNext(event:Event): void{
    	trace(">>");
    	if (_mc.currentFrame+3>_mc.totalFrames) {
    		_mc.gotoAndStop(1);
    	} else {
    		_mc.gotoAndStop(_mc.currentFrame+1);
    	}
    }
    
    function mcBack(event:Event): void{
    	trace("<<");
    	if (_mc.currentFrame-3<1) {
    		_mc.gotoAndStop(_mc.totalFrames);
    	} else {
    		_mc.gotoAndStop(_mc.currentFrame-1);
    	}
    }

    Can somebody please help me? Thankyou

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Fix your indentation, it's hard to read.

    First, you do not need the "new Number()" part when you declare oldXmouse. Second, do not declare a local variable oldXmouse in chkDrag. By doing so, you are NOT using the larger scoped oldXmouse. Change:
    Code:
    var oldXmouse:Number = MovieClip(root).mouseX;
    to
    Code:
    oldXmouse = MovieClip(root).mouseX;

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