Hello everybody,
I am encountering an issue I really can't find a solution to. When embedding assets in a class file and assigning them to a variable of the Class type, I get a compiler error 1000 "Ambiguous Reference". This ONLY happens when I move the class file into a package. Leaving the class file in the main source folder results in no errors, but I am not satisfied with this solution. Here's the source code for one of my classes.
(EDIT)
Some clarifications:
I am not using any namespaces, at least not explicitly.
My first assumption was there would be a problem with the build path, so I added the "assets" folder to the project paths and tried referencing the embedded files directly (just source="filename.png"). Again, this works flawlessly from the default package, but not from any other package.
Flash Builder 4.5 shows two errors for each embedded asset. These for example relate to IMG_COMPASS_ARROW:
1000: Ambiguous reference to GravityCompass_IMG_COMPASS_ARROW.
Can not resolve a multiname reference unambiguously. GravityCompass_IMG_COMPASS_ARROW (from GravityCompass_IMG_COMPASS_ARROW.as) and comp:GravityCompass_IMG_COMPASS_ARROW (from comp\GravityCompass_IMG_COMPASS_ARROW.as) are available.
ActionScript Code:
package comp
{
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.geom.Point;
import mx.core.UIComponent;
public class GravityCompass extends UIComponent
{
[Embed(source="assets/img_compass_bg.png")]
private static const IMG_COMPASS_BG:Class;
[Embed(source="assets/img_compass_arrow.png")]
private static const IMG_COMPASS_ARROW:Class;
private var _backgroundImage:Bitmap;
private var _arrowImage:Bitmap;
private var _arrowRotation:Number;
private var _bgCenterX:Number;
private var _bgCenterY:Number;
private var _arrowCenterX:Number;
private var _arrowCenterY:Number;
public function GravityCompass()
{
super();
}
override protected function createChildren():void {
_backgroundImage = new IMG_COMPASS_BG();
_arrowImage = new IMG_COMPASS_ARROW();
_bgCenterX = .5 * _backgroundImage.width;
_bgCenterY = .5 * _backgroundImage.height;
_arrowCenterX = .5 * _arrowImage.width;
_arrowCenterY = .5 * _arrowImage.height;
_arrowImage.x = _bgCenterX - _arrowCenterX;
_arrowImage.y = _bgCenterY - _arrowCenterY;
addChild(_backgroundImage);
addChild(_arrowImage);
}
override protected function measure():void {
measuredWidth = _backgroundImage.width;
measuredHeight = _backgroundImage.height;
measuredMinWidth = _backgroundImage.width;
measuredMinHeight = _backgroundImage.height;
}
public function set direction(p:Point):void {
// Calculating the angle between p and the upward
// pointing vector (0, -1) using the well known formula
// cos(angle) = v1 * v2 / |v1| * |v2|
var angle:Number = Math.acos(-p.y / p.length);
if(p.x < 0) {
angle = -angle;
}
var m:Matrix = new Matrix();
// Moving the graphic's center to the origin
m.translate(-_arrowCenterX, -_arrowCenterY);
// Rotating around the origin
m.rotate(angle);
// Moving the graphic's center back
m.translate(_arrowCenterX, _arrowCenterY);
// Then move it to the background graphic's center
m.translate(_bgCenterX-_arrowCenterX, _bgCenterY-_arrowCenterY);
// Write the result back to the graphic's transform matrix
_arrowImage.transform.matrix = m;
}
}
}