3 of 3
3
Simple Flash Client? 
Posted: 26 July 2008 05:36 PM   [ Ignore ]   [ # 31 ]
Jr. Member
RankRank
Total Posts:  146
Joined  2008-05-31

http://nuigroup.com/wiki/Building_Your_First_Application/

So if someone can tell me the wiki software we are running here, I can find out how to make it much much better.

1: create a new Flash file (actionScript3)
2: click on the canvas, the properties for the file should not be available.
3:click on the size button.
4: change that to 1024 x 768 and 30+ FPS
5: click settings (below size button)
6: Where it says actionScrtip version, make sure ActionScript is selected and click settings
7: in classpath at the bottom, click on the + button and enter
../ext
do the same for
../int
8: save this flash file in (the touchlib folder) AS3/src (name it what you want) EG touch.fla
9: in the AS3/int/app/demo folder, create a new folder called MyTouchApp (must be exact)

10: create a new ActionScript file.
11: save it as MyTouchApp.as in AS3/int/app/demo/MyTouchApp (that folder you just made)
12: go back to (click on the tab for) you flash file EG. touch.fla

13: In the Document Class text field enter app.demo.MyTouchApp.MyTouchApp

14: select the rectangle button and make a rectangle that is over, and larger than your canvas. This will be the area your program will run on.
15: right click (control click on a mac) on the black rectangle you just made and select “Convert To Symbol”
16: make sure movieclip is selected and press ok.
17: Save file… go back to MyTouchApp.as
18: copy code from examples and paste it in this file. MAKE SURE THE PAGE IS CLEARED FIRST
19: save this file again, go back to (click on the tab for) you flash file EG. touch.fla

20: publish the file. It should work now

You need to create a new fla fie and a new .as file.

in the properties of the fla click settings (next to “publish:")
next to the drop down for actionscript version, click on settings
at the bottom for classpath hit plus sign and enter
../int
and the same again for:
../ext

save the fla file in (the touchlib folder) AS3/src (name it what you want)
save the .as file in AS3/int/app/demo (name it MyTouchApp.as )

in the fla file in properties window, for the Document class enter
app/demo/MyTouchApp.as

it should have no error… click the pencil button next to it, and it should take you to your .as file if it worked properly.

They are now linked.

In the as file use this code.

Profile
 
 
Posted: 26 July 2008 06:25 PM   [ Ignore ]   [ # 32 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  596
Joined  2008-02-12

noverflow i optimised your original AS3 code, it does everything you did in flash in AS3 however this handles both touch and mouse inputs together… i would have done it sooner but i’ve been a bit busy… anyway here it is.

package  
{    
    
/**
    * Draws circles where touch or mouse input is detected
    */
    
    // Importing depdencies
    
import flash.events.*;
    
import flash.display.*;
    
import app.core.element.Wrapper;
        
    public class 
touchMarker extends Sprite
    {
        
//initialising variables
        
private var stage_:Sprite//stage sprite
        
private var wrapperObj:Wrapper//wrapper that converts interpertes touch events as mouse events.
        
private var circle:Sprite// display circle
        
        
public function touchMarker() 
        
{
            stage_ 
= new Sprite(); //initialising stage
            
            // Drawing empty sprite
            
stage_.graphics.beginFill(0xffffff,0.0);        
            
stage_.graphics.drawRect( -0, -0stage.fullScreenWidthstage.fullScreenHeight);
            
            
wrapperObj = new Wrapper(stage_//initialising wrapperObj and loading the closeBtn within wapperObj
            
wrapperObj.addEventListener(MouseEvent.MOUSE_DOWNdrawCircle); //adding event listner at MouseClick, Wrapper object converts touch inputs into mouse inputs
            //wrapperObj.addEventListener(MouseEvent.MOUSE_UP, removeCircle); //Hide circle
        
            
this.addChild(wrapperObj); // adding wrapperObj to the stage where wrapperObj contains closeBtn
        
            /**
             * Initialising TUIO Protocol
             * communicate with touchlib, and recogonise touch inputs 
             */
            
TUIO.initthis'localhost'3000''true );
        
}
        
        
// private function that draws a circle where an input has been detected.
        
private function drawCircle(e:Event):void
        {
            
            circle 
= new Sprite();
            
circle.graphics.lineStyle(100xff0000); //set line width to 10px and red
            
circle.graphics.drawCircle(0,0,40); // draw a 40px circle
             
            //put it where the mouse clicked
            
circle.mouseX;
            
circle.mouseY;
            
            
this.addChild(circle); //add the circle to the plane
            
            
trace(circle.xcircle.y); //trace x & y co-ordinates of inputs
            
        
}
        
/*
        //Hide Circle function
        private function removeCircle(e:Event):void 
        {
         this.removeChild(circle);
        }*/
    
}
    
}

hope this works for you i dont use FlashCS3 a lot so i dont know if this will work in that but it works in FlashDevelop

 Signature 

My MultiTouch Blog

Profile
 
 
Posted: 27 July 2008 08:21 AM   [ Ignore ]   [ # 33 ]
Jr. Member
RankRank
Total Posts:  146
Joined  2008-05-31

I had to change some stuff to make it work mainly fullScreenWidth, and fullScreenHeight to stage.stageWidth and stage.stageHeight
and to keep in the same fashion as the other code

package app.demo.MyTouchApp{//Draws circles where touch or mouse input is detected


    // Importing depdencies
    
import flash.events.*;
    
import flash.display.*;
    
import app.core.element.Wrapper;

    public class 
MyTouchApp extends Sprite {

        
//initialising variables
        
private var stage_:Sprite;//stage sprite
        
private var wrapperObj:Wrapper;//wrapper that converts interpertes touch events as mouse events.
        
private var circle:Sprite;// display circle
                
        
public function MyTouchApp() {
            stage_ 
= new Sprite();//initialising stage

            // Drawing empty sprite
            
stage_.graphics.beginFill(0xffffff,0.0);
            
stage_.graphics.drawRect( -0, -0stage.stageWidthstage.stageHeight);

            
wrapperObj = new Wrapper(stage_);//initialising wrapperObj and loading the closeBtn within wapperObj
            
wrapperObj.addEventListener(MouseEvent.MOUSE_DOWNdrawCircle);//adding event listner at MouseClick, Wrapper object converts touch inputs into mouse inputs
            //wrapperObj.addEventListener(MouseEvent.MOUSE_UP, removeCircle); //Hide circle -- comment out to disable and leave circles after up.

            
this.addChild(wrapperObj);// adding wrapperObj to the stage where wrapperObj contains closeBtn

            //--------connect to TUIO-----------------
            
TUIO.init(this,'localhost',3000,'',true);
            
trace("MyTouchApp Initialized");
            
//----------------------------------------       
        
}
        
// private function that draws a circle where an input has been detected.
        
private function drawCircle(e:Event):void {

            circle 
= new Sprite();
            
circle.graphics.lineStyle(100xff0000);//set line width to 10px and red
            
circle.graphics.drawCircle(0,0,40);// draw a 40px circle

            //put it where the mouse clicked            
            
circle.mouseX;
            
circle.mouseY;

            
this.addChild(circle);//add the circle to the plane

            
trace(circle.xcircle.y);//trace x & y co-ordinates of inputs

        
}
        
//Hide Circle function
        
private function removeCircle(event:Event):void {
            this
.removeChild(circle);
        
}
    }
}

Profile
 
 
Posted: 27 July 2008 11:03 AM   [ Ignore ]   [ # 34 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  596
Joined  2008-02-12

well by doing what you did, when you go in to full screen you have to be careful where you click cause it wont work everywhere on the screen, if your screen resolution is larger than that of the stage resolution, thats about it.
the so it works then ?

 Signature 

My MultiTouch Blog

Profile
 
 
Posted: 27 July 2008 02:44 PM   [ Ignore ]   [ # 35 ]
Jr. Member
RankRank
Total Posts:  146
Joined  2008-05-31

It works… but the x,y do not register.
It places the circles where the mouse is.

fullScreenWidth didnt register, and said it didnt know what it was.

Taha - 27 July 2008 11:03 AM

well by doing what you did what you did, when you go in to full screen you have to be careful where you click cause it wont work everywhere on the screen thats about it.
the so it works then ?

Profile
 
 
Posted: 22 September 2008 12:35 AM   [ Ignore ]   [ # 36 ]
New Member
Rank
Total Posts:  7
Joined  2008-09-21
noverflow - 25 July 2008 05:09 AM

I posted this.
It is different.


package app.demo.MyTouchApp{ //adds a circle where you touch (no resize)

    
import flash.display.*;        
    
import flash.events.*;
    
import flash.net.*;
    
import flash.geom.*;  

    public class 
MyTouchApp extends Sprite {

        
public function MyTouchApp() {

            
//--------connect to TUIO-----------------
            
TUIO.init(this,'localhost',3000,'',true);
            
trace("MyTouchApp Initialized");
            
//----------------------------------------        

            
addEventListener(TouchEvent.MOUSE_DOWNtouchDown); //run touchdown, when touched
        
}
        
        
public function touchDown(e:TouchEvent):void{        
                        
            
var curPt:Point parent.globalToLocal(new Point(e.stageXe.stageY)); //convert touch points to x,y                
            
            
var circle:Sprite = new Sprite(); //create a new sprite
            
            
circle.graphics.lineStyle(100xff0000); //set line width to 10px and red
            
circle.graphics.drawCircle(0,0,40); // draw a 40px circle
            
circle.curPt.x//put it where touch is (x cord)
            
circle.curPt.y//put it where touch is (y cord)

            
addChild(circle); //add the circle where touch happened
            
        
}
    }
}

I was trying the example code above in FlashDevelop and from the code I believe I should be getting red circle without filling on the point where I touch. The problem is I’m getting magenta filled circles that are a little offset to the right and down from where I touch. As I move closer to the top left corner of the screen, the offset is lesser. What seems to be wrong?

I realized the touchDown() event handler wasn’t even fired and the magenta dots must have come from TUIO.init()?

Profile
 
 
Posted: 22 September 2008 05:11 AM   [ Ignore ]   [ # 37 ]
Jr. Member
RankRank
Total Posts:  146
Joined  2008-05-31

Weird.
I have no clue why they would be filed. You are using graphcs.lineStyle and not graphics.beginFill right?

circle.graphics.lineStyle(10, 0xff0000); //set line width to 10px and red
circle.graphics.drawCircle(0,0,40); // draw a 40px circle

As for the offset. Are you in full screen mode when you are testing it? If not, try that.
If so, is it fine on other programs?

knng - 22 September 2008 12:35 AM

noverflow - 25 July 2008 05:09 AM
I posted this.
It is different.


package app.demo.MyTouchApp{ //adds a circle where you touch (no resize)

    
import flash.display.*;        
    
import flash.events.*;
    
import flash.net.*;
    
import flash.geom.*;  

    public class 
MyTouchApp extends Sprite {

        
public function MyTouchApp() {

            
//--------connect to TUIO-----------------
            
TUIO.init(this,'localhost',3000,'',true);
            
trace("MyTouchApp Initialized");
            
//----------------------------------------        

            
addEventListener(TouchEvent.MOUSE_DOWNtouchDown); //run touchdown, when touched
        
}
        
        
public function touchDown(e:TouchEvent):void{        
                        
            
var curPt:Point parent.globalToLocal(new Point(e.stageXe.stageY)); //convert touch points to x,y                
            
            
var circle:Sprite = new Sprite(); //create a new sprite
            
            
circle.graphics.lineStyle(100xff0000); //set line width to 10px and red
            
circle.graphics.drawCircle(0,0,40); // draw a 40px circle
            
circle.curPt.x//put it where touch is (x cord)
            
circle.curPt.y//put it where touch is (y cord)

            
addChild(circle); //add the circle where touch happened
            
        
}
    }
}

I was trying the example code above in FlashDevelop and from the code I believe I should be getting red circle without filling on the point where I touch. The problem is I’m getting magenta filled circles that are a little offset to the right and down from where I touch. As I move closer to the top left corner of the screen, the offset is lesser. What seems to be wrong?

I realized the touchDown() event handler wasn’t even fired and the magenta dots must have come from TUIO.init()?

Profile
 
 
Posted: 22 September 2008 06:15 PM   [ Ignore ]   [ # 38 ]
New Member
Rank
Total Posts:  12
Joined  2008-07-02
noverflow - 22 September 2008 05:11 AM

Weird.
I have no clue why they would be filed. You are using graphcs.lineStyle and not graphics.beginFill right?

circle.graphics.lineStyle(10, 0xff0000); //set line width to 10px and red
circle.graphics.drawCircle(0,0,40); // draw a 40px circle


As for the offset. Are you in full screen mode when you are testing it? If not, try that.
If so, is it fine on other programs?

I discovered that the touchDown() event is not fired and I experimented with putting a background sprite to make it activate the event. I’m guessing could the code be a class to a FLA files which provides a background canvas? When I ran it in FlashDevelop, I do not have the FLA so I need to put a background sprite?

I also discovered that the magenta filled circles were always there just by the TUIO.init() function. The only thing I don’t understand is the offset in the circle position from the actual touch. My FTIR works fine with the flash samples from touchlib.

Profile
 
 
   
3 of 3
3