Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rate Thread Display Modes
Old 01-07-2012, 11:16 AM   #1
Wastelander
Registered User
 
Join Date: Jun 2006
Posts: 4
Red face Error 1000: Ambiguous Reference when embedding from a package

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;         }     } }

Last edited by Wastelander; 01-07-2012 at 11:34 AM.
Wastelander is offline   Reply With Quote
Old 01-07-2012, 03:07 PM   #2
tadster
tadster
 
tadster's Avatar
 
Join Date: Feb 2009
Location: Texas
Posts: 2,111
Default

Do you still have a GravityCompass class in the main source folder?

Edit: May also be the static declaration used on the embeds.
__________________
www.actiontad.com - ActionScript and JavaScript sitting in a tree...
tadster is offline   Reply With Quote
Old 01-07-2012, 05:58 PM   #3
Wastelander
Registered User
 
Join Date: Jun 2006
Posts: 4
Default

I solved the problem, although the solution isn't very satisfying. When moving the assets to the same directory as the class file it works. It seems that Flex internally declares a Class object in the directory where the file is located and thus creates TWO Class objects of the same name. Looks like a bug to me, especially since the two Class objects are in different packages and thus should have different namespaces implicitly.
Wastelander is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT. The time now is 09:25 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.