Importing flash project to actionscript mobile project in flash builder.

profilebbows133
slingshot.zip

SlingShot/._slingShot.swf

SlingShot/accelerometer.as

import flash.sensors.Accelerometer; var theAcc:Accelerometer = new Accelerometer(); theAcc.setRequestedUpdateInterval(50); if (Accelerometer.isSupported == true) { trace("is supported"); } else { //do something if its not //instructions.visible = flase } theAcc.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate); function onAccUpdate(event:AccelerometerEvent):void { if (ball.x > point2.x) { vel.x -= (event.accelerationX * 1); } }

SlingShot/clockTimer.as

SlingShot/collisions.as

function detectCollisions() { //block collision if (blockOutline.hitTestPoint(ball.x,ball.y,true)) { hitblockOutline = true; vel.x = vel.x * -1; } //box collision if (outline.hitTestPoint(ball.x,ball.y,true) && hitOutline == false) { hitOutline = true; vel.x = vel.x * -1; } //the target if (theTarget.hitTestPoint(ball.x,ball.y,true) && ball.visible == true) { ball.visible = false; acc.x = 0; acc.y = 0; vel.x = 0; vel.y = 0; trace ("you win"); resetPlay(); } }

SlingShot/doConstantly.as

import flash.events.Event; addEventListener(Event.ENTER_FRAME, doConstantly); function doConstantly(event:Event):void { //main code for gravity affect ball and other stuff... acc.x = 0; acc.y = gravity; if (released == true) { //if you have let go of ball /*vel.x += acc.x; vel.y += acc.y;*/ ball.x += vel.x; ball.y += vel.y; //ball.rotation += vel.x; } //this will make sure the ball doesnt dissappear off stage if (ball.x > stage.stageWidth || ball.x < 0 || ball.y < -500 || ball.y > stage.stageHeight + 100) { resetPlay(); } //below draw elastic string elastic.graphics.clear(); elastic.graphics.lineStyle(0.5, 0x9999999); if (ball.y > point1.y && ball.x < point2.x) {// the ball falls within range of bending the string forced = true; var x1:Number = ball.x - point1.x; var y1:Number = ball.y - point1.y; var x2:Number = point2.x - ball.x; var y2:Number = point2.y - ball.y; var distance1:Number = Math.sqrt(x1*x1+y1*y1); var distance2:Number = Math.sqrt(x2*x2+y2*y2); angle1 = Math.atan2(y1,x1); angle2 = Math.atan2(y2,x2); var xOffset:Number = Math.cos(angle1+Math.PI/2)*radius; var yOffset:Number = Math.sin(angle1+Math.PI/2)*radius; var xOffset2:Number = Math.cos(angle2+Math.PI/2)*radius; var yOffset2:Number = Math.sin(angle2+Math.PI/2)*radius; angle1 += Math.sin(radius/distance1); angle2 += Math.sin(radius/distance2)*-1; elastic.graphics.moveTo(point1.x, point1.y); elastic.graphics.lineTo(ball.x+xOffset, ball.y+yOffset); elastic.graphics.moveTo(point2.x, point2.y); elastic.graphics.lineTo(ball.x+xOffset2, ball.y+yOffset2); } else { // the ball falls out of range of bending the string; forced = false; elastic.graphics.moveTo(point1.x, point1.y); elastic.graphics.lineTo(point2.x, point2.y); } // makes the ball bounce back up; if (released == true && forced == true) { acc.x += distance1 * Math.sin(angle2) * elasticCoefficient; acc.y += - distance1 * Math.cos(angle1) * elasticCoefficient; acc.x += distance2 * Math.sin(angle1) * elasticCoefficient; acc.y += - distance2 * Math.cos(angle2) * elasticCoefficient; } if (released) { vel.x += acc.x; vel.y += acc.y; } //prevent you from moving can over the target if (released == false && ball.x >point2.x) { ball.stopDrag(); released = true; resetPlay(); } //calling collision functions detectCollisions(); }

SlingShot/initials.as

import flash.display.MovieClip; import flash.events.Event; import flash.sensors.Accelerometer; import flash.events.AccelerometerEvent; stop(); var blockStarting:Object = {x:block.x , y:block.y}; var ballStarting:Object = {x:ball.x , y:ball.y}; trace (ballStarting.x, ballStarting.y); var stick1Starting:Object = {x:stick1.x, y:stick1.y}; var stick2Starting:Object = {x:stick2.x, y:stick2.y}; var point1Starting:Object = {x:point1.x, y:point1.y}; var point2Starting:Object = {x:point2.x, y:point2.y}; var boxStarting:Object ={x:box.x, y:box.y}; //trace (boxStarting.x, boxStarting.y); var theTargetStarting:Object = {x:theTarget.x, y:theTarget.y}; //trace (theTargetStarting.x, theTargetStarting.y); var gravity = 0.15; var angle1:Number = 0; var angle2:Number = 0; var radius:Number = 1; var elasticCoefficient:Number = 0.0045; var released:Boolean = true; var forced:Boolean = false; //whether or not it is being pulled down between the sticks var acc:Object = {x:0, y:0}; var vel:Object = {x:0, y:0}; var hitOutline:Boolean = false; var hitblockOutline:Boolean = false; var hittheTarget:Boolean = false; var elastic:MovieClip = new MovieClip(); addChild (elastic);

SlingShot/mouseEvents.as

import flash.events.MouseEvent; ball.addEventListener (MouseEvent.MOUSE_DOWN, ballDown); function ballDown(event:MouseEvent) { resetPlay(); ball.x = mouseX; ball.y = mouseY; ball.startDrag(); released = false;//gravity will not affect ball when false } stage.addEventListener (MouseEvent.MOUSE_UP, ballUp); function ballUp(event:MouseEvent) { ball.stopDrag(); released = true;// gravity will affect can }

SlingShot/resetPlay.as

function resetPlay() { hitblockOutline = false; hitOutline = false; hittheTarget = true; ball.x = 89.5; ball.y = 170.05; vel.x = 0; vel.y = 0; acc.x = 0; acc.y = gravity; block.x = blockStarting.x; block.y = blockStarting.y; point1.x = point1Starting.x; point1.y = point1Starting.y; point2.x = point2Starting.x; point2.y = point2Starting.y; stick1.x = stick1Starting.x; stick1.y = stick1Starting.y; stick2.x = stick2Starting.x; stick2.y = stick2Starting.y; box.x = boxStarting.x; box.y = boxStarting.y; theTarget.x = theTargetStarting.x; theTarget.y = theTargetStarting.y; }

SlingShot/slingShot.fla

SlingShot/slingShot.png

SlingShot/slingShot.swf

SlingShot/slingShot.xml