1180: Call to a possibly undefined method Point - actionscript-3

I'm very very new on ActionScript 3.0 development for Blackberry Playbook.
I'm working with Double Sided 3D Plane in FP10 and I'm having troubles with this code:
package
{
import flash.display.Sprite;
import flash.events.Event;
public class FlipCard extends Sprite
{
private var myPaperSprite:PaperSprite;
public function FlipCard()
{
super();
}
private function Flip():void
{
/*
Create a new PaperSprite:
If your front and back faces already exist, you can pass them straight
into the constructor, like so:
myPaperSprite = new PaperSprite( myFrontMc, myBackMc );
*/
myPaperSprite = new PaperSprite();
/*
Optionally specify a pivot point, in this example the centre is used
(this is also the default so there is no need to set this normally).
To pivot around the top left use:
myPaperSprite.pivot = new Point(0,0);
or for bottom right:
myPaperSprite.pivot = new Point(1,1);
and so on...
*/
myPaperSprite.pivot = new Point(0.5,0.5);
line myPaperSprite.pivot = new Point(0.5,0.5); is throwing the following error:
1180: Call to a possibly undefined method Point.
And pivot member is defined as follows:
package
{
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Rectangle;
public class PaperSprite extends Sprite
{
//___________________________________________________________
//————————————————————————————————————————————— CLASS MEMBERS
private static const POINT_A:Point = new Point(0, 0);
private static const POINT_B:Point = new Point(100, 0);
private static const POINT_C:Point = new Point(0, 100);
private var _isFrontFacing:Boolean = true;
private var _autoUpdate:Boolean = true;
private var _pivot:Point = new Point(0.5,0.5);
private var _front:DisplayObject;
private var _back:DisplayObject;
private var _p1:Point;
private var _p2:Point;
private var _p3:Point;
//___________________________________________________________
//————————————————————————————————————————— GETTERS + SETTERS
/**
* A Point Object used to determine the pivot, or registration point of the
* PaperSprite. The values should be between 0 and 1 and are relative to the
* dimensions of each face, 0 being far left (on the x axis) or top (y axis)
* and 1 being the far right (x axis) or bottom (y axis).
*
* The default value is { x:0.5, y:0.5 } meaning that both faces will pivot
* around their respective centres
*
* Examples:
*
* To pivot from the centre use: new Point( 0.5, 0.5 );
* To pivot from the top left use: new Point( 0.0, 0.0 );
* To Pivot from the bottom right use: new Point( 1.0, 1.0 );
*
*/
public function get pivot():Point
{
return _pivot;
}
public function set pivot( value:Point ):void
{
_pivot = value;
alignFaces();
}
Where is the problem? What am I doing wrong?

add import flash.geom.Point to FlipCard.as as well, as it is not visible in that class

Related

Accessing timers within a actionscript class

I recently started programming in as3, and lately, I've started to learn object oriented programming. My problem is to access functions within a class. I guess that the "main" code is not very suitable for doing so, but I'm pretty much just asking for advice for every part of the code.
Main Code:
import flash.utils.Timer;
import flash.events.TimerEvent;
stage.addEventListener(MouseEvent.CLICK, makeCircle);
function makeCircle(event:MouseEvent):void
{
var s = new Circle();
addChild(s);
s.x = mouseX;
s.y = mouseY;
}
Class code (connected to a MovieClip circle with a MovieClip fill inside):
package
{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
public class Circle extends MovieClip
{
private var t:Timer = new Timer(30,1000);
var time:Number = 0;
var size:Number;
var bf = new BlurFilter();
var ct:ColorTransform = new ColorTransform();
public function Circle()
{
// constructor code
t.addEventListener(TimerEvent.TIMER, updateCircle);
t.start();
ct.color = 0xffffff * Math.random();
fill.transform.colorTransform = ct;
fill.blendMode = "hardlight";
}
public function updateCircle(event:TimerEvent):void
{
time = t.currentCount / 10;
size = Math.pow(Math.E, - time) * Math.sin(5 * time) * (Math.log(time));
width = (size * 20 + 100 - time * 5) * 2;
height = (size * 20 + 100 - time * 5) * 2;
bf.blurX = time;
bf.blurY = time;
filters = [bf];
alpha = 1 - time / 20;
}
}
}
What I want to do is to remove the child of s (main code) when the t.currentCount (class code) is a set value (when the alpha value is 0).
Thanks in advance.
whay you want to do is do create either an even inside the Circle class that triggers when your timer completes (alpha == 0). The custom event would have to be caught in your main class.
To put a custom event listener in your main class write:
s.addEventListener("RemoveChild", removeChild)
add the handler function
function removeChild(e:Event)
{
removeChild(s);
}
in your circle class you can add the event when you want to trigger it:
this.dispatchEvent(new Event("RemoveChild");
Alternatively you control the Alpha value from your main class by placing the loop there and call removeChild(s); directly.
An easy way to get your custom events working is by using the AS3Signals framework.
Hope that helps

Actionscript 3.0 Perfect Collision Detection registration point center?

hey i have a problem with Collision Detection i used this example from a website http://www.freeactionscript.com/2009/05/pixel-perfect-collision-detection/ but it only works when your Object's registration point is on the upper left corner what should i change in the code if let's say the registration point is on the center?
here is the code:
package
{
import flash.display.BitmapData;
import flash.display.DisplayObjectContainer;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
public class CollisionTest
{
// vars
private var _returnValue:Boolean;
private var _onePoint:Point;
private var _twoPoint:Point;
private var _oneRectangle:Rectangle;
private var _twoRectangle:Rectangle;
private var _oneClipBmpData:BitmapData;
private var _twoClipBmpData:BitmapData;
private var _oneOffset:Matrix;
private var _twoOffset:Matrix;
/**
* Simple collision test. Use this for objects that are not rotated.
* #param clip1 Takes DisplayObjectContainer as argument. Can be a Sprite, MovieClip, etc.
* #param clip2 Takes DisplayObjectContainer as argument. Can be a Sprite, MovieClip, etc.
* #return Collision True/False
*/
public function simple(clip1:DisplayObjectContainer, clip2:DisplayObjectContainer):Boolean
{
_returnValue = false;
_oneRectangle = clip1.getBounds(clip1);
_oneClipBmpData = new BitmapData(_oneRectangle.width, _oneRectangle.height, true, 0);
_oneClipBmpData.draw(clip1);
_twoRectangle = clip2.getBounds(clip2);
_twoClipBmpData = new BitmapData(_twoRectangle.width, _twoRectangle.height, true, 0);
_twoClipBmpData.draw(clip2);
_onePoint = new Point(clip1.x, clip1.y)
_twoPoint = new Point(clip2.x, clip2.y)
if (_oneClipBmpData.hitTest(_onePoint, 255, _twoClipBmpData, _twoPoint, 255))
{
_returnValue = true;
}
return _returnValue;
}
/**
* Complex collision test. Use this for objects that are rotated, scaled, skewed, etc
* #param clip1 Takes DisplayObjectContainer as argument. Can be a Sprite, MovieClip, etc.
* #param clip2 Takes DisplayObjectContainer as argument. Can be a Sprite, MovieClip, etc.
* #return Collision True/False
*/
public function complex(clip1:DisplayObjectContainer, clip2:DisplayObjectContainer):Boolean
{
_returnValue = false;
_twoRectangle = clip1.getBounds(clip1);
_oneOffset = clip1.transform.matrix;
_oneOffset.tx = clip1.x - clip2.x;
_oneOffset.ty = clip1.y - clip2.y;
_twoClipBmpData = new BitmapData(_twoRectangle.width, _twoRectangle.height, true, 0);
_twoClipBmpData.draw(clip1, _oneOffset);
_oneRectangle = clip2.getBounds(clip2);
_oneClipBmpData = new BitmapData(_oneRectangle.width, _oneRectangle.height, true, 0);
_twoOffset = clip2.transform.matrix;
_twoOffset.tx = clip2.x - clip2.x;
_twoOffset.ty = clip2.y - clip2.y;
_oneClipBmpData.draw(clip2, _twoOffset);
_onePoint = new Point(_oneRectangle.x, _oneRectangle.y);
_twoPoint = new Point(_twoRectangle.x, _twoRectangle.y);
if(_oneClipBmpData.hitTest(_onePoint, 255, _twoClipBmpData, _twoPoint, 255))
{
_returnValue = true;
}
_twoClipBmpData.dispose();
_oneClipBmpData.dispose();
return _returnValue;
}
}
}
Well lets put it like this: How far away is the top left corner from the center point?
x += width * .5;
y += height * .5;
Right?
So if the code you posted above only treats it with top left (for whatever reason I don't know why) why not force it to treat it with center point instead?
Perhaps something like this?
_onePoint = new Point(clip1.x + _clip.width * .5, clip1.y + _clip.height * .5);
_twoPoint = new Point(clip2.x + _clip2.width * .5, clip2.y + _clip2.height * .5);

As3 magnify image

I want to create a image magnify application like following:
A masked small window showig big image area corresponding to the mouse X and Y on the small image. There are many magnifying image application exaples online such as:
http://www.flashandmath.com/intermediate/magglass/mag_glass.html
But here the mouse and mask moves with same X and Y. What i want is that masked window display only certain area corresponding to mouse X and Y on Small image.
Any help would be highly appreciated. thanks.
i wrote a recipe last year for exactly what you're looking for. i do not guarantee that's it's as refactored or efficient as it could be, but it works really well. change it up as much as you like. i post the code hear for anyone to freely use.
however, the photograph and loupe asset i do not permit anyone to use without prior request, please.
the class lets you alter your own magnification strength, even at runtime if you want. you can use your own loupe graphic, but one is also included in the source files (please ask me first if you want to use it in your project).
Description:
Magnifier: Creating A Customizable
Magnifier For Image Assets
The following code demonstrates the
solution for creating a customizable
magnifier for image assets using the
Magnifier class.
The Magnifier constructor receives 6
parameters. The first
loupeDisplayObject:DisplayObject
required parameter is a reference to a
display object that is used as the
virtual loupe. In order for the class
to function properly, the
loupeDisplayObject:DisplayObject must
contain a circular or elliptically
shaped void or alpha transparency at
its center.
The second imageURL:String required
parameter supplies the URLLoader’s
load function’s URLRequest with the
URL of the target image asset. The
image provides BitmapData for both
thumbSprite:Sprite and
magnificationSprite:Sprite objects,
which are scaled using the third
thumbScale:Number and fourth
magnificationScale:Number optional
parameters. The scale of the
thumbSprite:Sprite is exhibited on
stage, while the scale of the
magnificationSprite:Sprite is visible
during magnification.
The Magnifier class operates by
employing mouse events to toggle the
visibility of a virtual loupe over an
image asset. A maskSprite:Sprite
ellipse, both indexed below and based
on the size of the
loupeDisplayObject:DisplayObject, is
created to mask the
magnificationSprite:Sprite. However,
the fifth maskWidth:Number and sixth
maskHeight:Number optional parameters
can be set to manually size a
maskSprite:Sprite that is more
suitable for a
loupeDisplayObject:DisplayObject with
a complex shape.
Calling the public deallocate()
function of the Magnifier instance
prior to its nullification will mark
it as being available for garbage
collection.
Class FIle:
package
{
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.geom.Matrix;
import flash.net.URLRequest;
import flash.ui.Mouse;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.Regular;
public class Magnifier extends Sprite
{
//Class Variables
private var loupeDisplayObject:DisplayObject;
private var imageWidth:Number;
private var imageHeight:Number;
private var thumbScale:Number;
private var magnificationScale:Number;
private var maskWidth:Number;
private var maskHeight:Number;
private var imageBitmapData:BitmapData;
private var maskSprite:Sprite;
private var magnificationSprite:Sprite;
private var thumbSprite:Sprite;
private var loupeTween:Tween;
private var magnificationTween:Tween;
//Constructor
public function Magnifier (
loupeDisplayObject:DisplayObject,
imageURL:String,
thumbScale:Number = 0.5,
magnificationScale:Number = 1.0,
maskWidth:Number = NaN,
maskHeight:Number = NaN
)
{
this.loupeDisplayObject = loupeDisplayObject;
this.thumbScale = Math.max(0.1, Math.min(thumbScale, 1.0));
this.magnificationScale = Math.max(0.1, magnificationScale);
this.maskWidth = maskWidth;
this.maskHeight = maskHeight;
init(imageURL);
}
//Load And Handle Image
private function init(imageURL:String):void
{
var imageLoader:Loader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageHandler);
imageLoader.load(new URLRequest(imageURL));
}
private function errorHandler(evt:IOErrorEvent):void
{
throw(evt.text);
}
private function imageHandler(evt:Event):void
{
evt.target.removeEventListener(IOErrorEvent.IO_ERROR, errorHandler);
evt.target.removeEventListener(Event.COMPLETE, imageHandler);
imageWidth = evt.target.content.width;
imageHeight = evt.target.content.height;
imageBitmapData = new BitmapData(imageWidth, imageHeight);
imageBitmapData.draw(evt.target.content);
createComponents();
}
//Create Components
private function createComponents():void
{
//Loupe Visibility
loupeDisplayObject.alpha = 0;
//Mask
if (isNaN(maskWidth)) maskWidth = loupeDisplayObject.width;
if (isNaN(maskHeight)) maskHeight = loupeDisplayObject.height;
maskSprite = new Sprite();
maskSprite.graphics.beginFill(0x00FF00, 0.5);
maskSprite.graphics.drawEllipse(0, 0, maskWidth, maskHeight);
maskSprite.graphics.endFill();
maskSprite.mouseEnabled = false;
//Magnification
magnificationSprite = scaleImage(new Matrix(magnificationScale, 0, 0, magnificationScale));
magnificationSprite.mouseEnabled = false;
magnificationSprite.alpha = 0;
magnificationSprite.mask = maskSprite;
//Thumb
thumbSprite = scaleImage(new Matrix(thumbScale, 0, 0, thumbScale));
thumbSprite.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
//Add Components To The Display List
addChild(thumbSprite);
addChild(magnificationSprite);
addChild(maskSprite);
addChild(loupeDisplayObject);
}
private function scaleImage(matrix:Matrix):Sprite
{
var scaledResult:Sprite = new Sprite();
scaledResult.graphics.beginBitmapFill(imageBitmapData, matrix, false, true);
scaledResult.graphics.drawRect(0, 0, imageWidth * matrix.a, imageHeight * matrix.d);
scaledResult.graphics.endFill();
return scaledResult;
}
//Mouse Event Handlers
private function mouseDownHandler(evt:MouseEvent):void
{
thumbSprite.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
thumbSprite.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
mouseMoveHandler(evt);
setLoupeAsVisible(true);
}
private function mouseMoveHandler(evt:MouseEvent):void
{
loupeDisplayObject.x = evt.localX - loupeDisplayObject.width / 2;
loupeDisplayObject.y = evt.localY - loupeDisplayObject.height / 2;
maskSprite.x = evt.localX - maskSprite.width / 2;
maskSprite.y = evt.localY - maskSprite.height / 2;
magnificationSprite.x = 0 - evt.localX / thumbSprite.width * (magnificationSprite.width - thumbSprite.width);
magnificationSprite.y = 0 - evt.localY / thumbSprite.height * (magnificationSprite.height - thumbSprite.height);
}
private function mouseOutHandler(evt:MouseEvent):void
{
thumbSprite.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
setLoupeAsVisible(false);
}
private function mouseOverHandler(evt:MouseEvent):void
{
thumbSprite.removeEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
setLoupeAsVisible(true);
}
private function mouseUpHandler(evt:MouseEvent):void
{
if (thumbSprite.hasEventListener(MouseEvent.MOUSE_OVER)) thumbSprite.removeEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
thumbSprite.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
thumbSprite.removeEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
setLoupeAsVisible(false);
}
//Loupe Tween And Visibility
private function setLoupeAsVisible(response:Boolean):void
{
var targetAlpha:Number;
if (response)
{
targetAlpha = 1.0;
Mouse.hide();
}
else
{
targetAlpha = 0.0;
Mouse.show();
}
loupeTween = new Tween(loupeDisplayObject, "alpha", Regular.easeIn, loupeDisplayObject.alpha, targetAlpha, 0.25, true);
magnificationTween = new Tween(magnificationSprite, "alpha", Regular.easeIn, magnificationSprite.alpha, targetAlpha, 0.25, true);
}
//Clean Up
public function deallocate():void
{
thumbSprite.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
}
}
}

as3 - how to add multi custom class into one asset?

I'm a new mem of as3. Today i make a work but i was stacked. pls help me:
My example:
• I have a Symbol in Library with linkage name: box_mc
import flash.display.MovieClip;
import flash.events.Event;
import Src.smoothAnimate;
var box_is:MovieClip = new box_mc();
box_is.name = 'box_na';
addChild(box_is);
var box_is:smoothAnimate = new smoothAnimate(); // ERROR 1151 HERE
• i have a custom class :
package Src
{
import flash.display.*;
import flash.events.Event;
/**
* ...
* #author Trunglvt
*/
public class smoothAnimate extends MovieClip
{
private var currentW:Number;
private var currentH:Number;
private var endX:Number;
private var endY:Number;
private var sp:Number;
function smoothAnimate() {
trace('trace');
}
public function changeSize(speed:Number, newW:Number, newH:Number) {
trace('test');
this.endX = newW; // get new size
this.endY = newH;
this.sp = speed;
this.addEventListener(Event.ENTER_FRAME, onFrame);
}
private function onFrame(e:Event) {
e.target.currentW = e.target.width;
e.target.currentH = e.target.height;
e.target.width += (e.target.endX - e.target.currentW) * e.target.sp;
e.target.height += (e.target.endY - e.target.currentH) * e.target.sp;
if (Math.floor(e.target.width) == Math.floor(e.target.endX) ||
Math.floor(e.target.height) == Math.floor(e.target.endY)) {
//stop function enterFrame here;
removeEventListener(Event.ENTER_FRAME, onFrame);
}
}
}
}
but when run is make error:
1151: A conflict exists with definition box_is in namespace internal.
i want when flash run, the box_is will be add in stage, resize by function changesize.
Pls help me.
Thank you.
When you say:
var box_is:smoothAnimate = new smoothAnimate();
This declaration will error. You previously declared box_is when you said:
var box_is:MovieClip = new box_mc();
Two var cannot have the same name in the same scope.
If you want to reuse the box_is symbol, don't use var. Just reassign box_is:
box_is = new smoothAnimate();

PaperVision3D and Flash CS4

I need to develop a cube that contain 10 little cubes and manipulate everyone like an object..Somebody have any idea or some tutorial for do this on PaperVision3d and Flash CS4..Thanks Folks!!
I think what you actually want is Papervision3d as I know of nothing called "PaperViewer". If that is the case, please update your question.
This should give you an idea of how to start. It creates 10 cubes and stores them in an array. You can access them using boxes[index] to alter their scale, postion and rotation.
package
{
import flash.display.Sprite;
import flash.events.Event;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.view.BasicView;
public class Boxes3d extends Sprite
{
private static const NUM_BOXES:int = 10;
private var world:BasicView;
private var boxes:Array;
public function Boxes3d()
{
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
private function addedToStage(event:Event):void
{
// create the world and add it to the stage
world = new BasicView();
addChild(world);
// create a set of boxes
boxes = [];
var box:Cube;
var materials:MaterialsList;
for(var boxIndex:int = 0; boxIndex < NUM_BOXES; boxIndex++)
{
// create a material to cover the cube
materials = new MaterialsList({
all: new ColorMaterial(Math.random()*0xFFFFFF) });
// make a cube
box = new Cube(materials, 100, 100, 100);
// spread it out in space
box.x = Math.random()*500 - 250;
box.y = Math.random()*500 - 250;
box.z = Math.random()*500 - 250;
// add it to the scene
world.scene.addChild(box);
}
// get the world to render each frame
world.startRendering();
addEventListener(Event.ENTER_FRAME, positionCamera);
}
private function positionCamera(event:Event):void
{
var camera:Camera3D = world.cameraAsCamera3D;
camera.x = -(stage.width/2 - mouseX) * 2;
camera.y = (stage.height/2 - mouseY) * 2;
}
}
}