Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-18-2008, 08:44 AM
Junior Member
 
Join Date: Jan 2008
Posts: 4
Default Drag & drop ?

Hello, I'm making a screen toy, which moves upon windows and may be draggable.
First, I'd like to congratulate you for your product which is, so far, the best one I have tested.

Naturally, with a setInterval, the main window moves around the screen (falling, running...). Everything written in FFish script. But I would like this natural movement to stop when the user wants to drag the window.
The problem is that I can't find an event such as onDrag or onClick. If I use a button in my swf to catch this event (and then tell SWFKit to stop the natural movement of the window), the draggable behaviour will be overwritten... I can't afford sending value of the current mouse position to SWFKit from the swf to emulate a drag, I believe this would be a hudge slowdown...

Well if you understand my problem, thank you in advance for your answer.
Reply With Quote
  #2 (permalink)  
Old 02-18-2008, 06:23 PM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re: Drag & drop ?

You can handle the "onMessage" event of the flash player window. Kill the timer when left mouse button has been clicked.

Code:
//Initialize
getAdditionalFile();

//GetWindows
var c__desktopLeft = 0;
var c__desktopTop = 0;
var c__height = 100;
var c__width = 100;
var c__currentApp = "Buddy";
var c__g = 1;
var c__friction = .2;
var c__walkingSpeed = 2;
var c__desktopRight = SysInfo.displaySetting.pelsWidth;
var c__desktopBottom = SysInfo.displaySetting.pelsHeight;

var l__chosenWindowRect = new Object();
var l__currentWindows;
var l__windowRect;

function checkIfCollides(i__x, i__y)
{
	l__currentWindows = Window.getWindowsByName();
	l__chosenWindowRect.top = 0;
	
	for (var i=l__currentWindows.length-1; i>=0; i--) 
	{
		l__windowRect = l__currentWindows[i];
	
		if (!l__windowRect.visible || l__windowRect.caption == c__currentApp)
			continue;
				
		if (i__x > l__windowRect.left-c__width && i__x < l__windowRect.left+l__windowRect.width 
			&& i__y+c__height < l__windowRect.top+10 && i__y+c__height >= l__windowRect.top)
		{
			l__chosenWindowRect.top = l__windowRect.top;
			l__returnValue = l__windowRect.top-c__height;
			
		}
		else
		//si la fenêtre actuelle recouvre la fenêtre choisie, on annule
		if (l__windowRect.left+l__windowRect.width >i__x && l__windowRect.left<i__x 
			&& l__windowRect.top < l__chosenWindowRect.top && l__windowRect.top+l__windowRect.height > l__chosenWindowRect.top)
		{
			l__returnValue = i__y;
		}
		delete l__currentWindows[i];
		delete l__windowRect;
	}
	delete i;
	delete l__chosenWindowRect;
	if (i__y > c__desktopBottom-c__height)
		l__returnValue = c__desktopBottom-c__height;	
		
	//il faut éviter qu'il reste coincé au-dessus des fenêtres plein écran		
	if (i__y <= c__desktopTop-c__height)
		l__returnValue = c__desktopTop-c__height+10;
	
	delete l__currentWindows;
	return l__returnValue;
}

var m__computedY = 0;
var m__y = 10;
var g__currentAnim = "vol";
var m__x = 10;
var m__computedX = 0;
var m__speedY = 0;
var m__speedX = 0;

function fallEnterFrame()
{
	m__computedY = m__y;
	m__speedY += c__g;
	m__speedY = Math.min(m__speedY, 9);
	m__speedY = Math.max(m__speedY, -20);
	m__computedY += m__speedY;	
	
	//si ça tombe, il faut faire attention aux fenêtres
	if ( m__speedY > 0)
	{
		m__y = checkIfCollides(m__x, m__computedY);
	}
	else
	{	
		m__y = m__computedY;
	}
			
	m__computedX = m__x;
	m__speedX = Math.min(m__speedX, 20);
	m__speedX = Math.max(m__speedX, -20);
	m__computedX += m__speedX;
	
	//le machin est posé
	if (m__computedY != m__y)
	{
		m__speedY = 0;
		m__speedX = 0;
		m__x = m__x+c__walkingSpeed;
			
		if (g__currentAnim == "vol")		
			g__currentAnim = "aterrissage";					
		else
			g__currentAnim = "marche";		
	}
	else
	{
		m__x = m__computedX;
		g__currentAnim = "vol";
	}
	FlashPlayer.setVariable("_root.g__currentAnim", g__currentAnim);
	
	if (m__x > c__desktopRight)
	{
		if (m__y == c__desktopBottom-c__height)
		{
			m__y = c__desktopTop;
			m__x = c__desktopLeft+Math.random()*((c__desktopRight-c__width)-c__desktopLeft)
		}
		else		
			m__x = c__desktopLeft;
	}
	
	if (m__x < c__desktopLeft)
	{
		if (m__y == c__desktopBottom-c__height)
		{
			m__y = c__desktopTop;
			m__x = c__desktopLeft+Math.random()*((c__desktopRight-c__width)-c__desktopLeft)
		}
		else
			m__x = c__desktopRight;		
	}
	
	Application.SizeAndPos.setCustomPos(parseInt(m__x), parseInt(m__y));
}

timer = Application.setInterval(fallEnterFrame, 20);

var last_x, last_y;
FlashPlayer.window.onMessage = function (msg, wparam, lparam) {
	if (msg == /*WM_LBUTTONDOWN*/0x201) {
		Application.clearInterval(timer);
		last_x = getMainWnd().left;
		last_y = getMainWnd().top;
	} else if (msg == /*WM_LBUTTONUP*/0x202) {
		m__x += getMainWnd().left - last_x;
		m__y += getMainWnd().top - last_y;
		timer = Application.setInterval(fallEnterFrame, 20);
	}
}

return true;
Reply With Quote
  #3 (permalink)  
Old 02-19-2008, 11:41 AM
Junior Member
 
Join Date: Jan 2008
Posts: 4
Default Re: Drag & drop ?

Amazing, thank you very much!
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:00 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.