Vectorian Giotto import flash.external.ExternalInterface syntax error? - actionscript-3

I'm creating a scaleform HUD for UDK, and everything is created. The problem is that i want the healthbar and weapons bar to rotate slightly to give a 3d effect. When I try to do this i get 2 errors:
on line 1, Characters 1-2, Syntax Error: i
on line 6, CHaracters 1-10, Syntax error: intrinsic
import flash.external.ExternalInterface
import gfx.motion.Tween
_global.gfxExtension = true;
function init()
{
_root.HealthBar._yrotation = 30;
_root.Weapons._yrotation = 30;
}
init();
Is it because this is for actionscript 3.0? how would i convert it to 2.0? Thank You

Take a look at this thread, which talks about some challenges with using ExternalInterface: http://forums.epicgames.com/threads/802762-Developing-Scaleform-UI-with-Vectorian-Giotto

Related

StageWebView in an AS3-Script

I allreday read a lot of helpful stuff in that forum. Now it's my first time I ask for specific help.
I'm pretty new to Flash and have a problem I struggle for more then a week now. The most efficient and elegant way for my problem is to put a StageWebView-Call into an as-File.
That would be the plan:
In my flash-File: Show a PDF document "xyz" and put it on the stage.
I alreday tried it with Switch-Case - But then I have trouble to get rid of the PDF's.
That was my Idea:
First the new as-File...
package {
import flash.display.MovieClip;
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.filesystem.File;
import flash.display.Sprite;
import flash.display.Stage;
public class mypdf {
public var MyWebView:StageWebView
public var file:String
public var pdf:File
public function mypdf(ActFile:String) {
MyWebView = new StageWebView();
file = ActualFile; //MARKING #1
pdf = File.applicationDirectory.resolvePath(file);
MyWebView.stage = stage; //MARKING #2
MyWebView.viewPort = new Rectangle (200, 200, 400, 400);
MyWebView.loadURL(pdf.nativePath);
}
}
}
Than I want to call that in my flash-File...
stop();
var mynewpdf:mypdf = new mypdf("test.pdf");
Two erros are shown:
1120: Access of undefined property error ActualFile (at Marking #1)
1120: Access of undefined property error Stage (at Marking #2)
With a lot more work I could avoid the first error by defining a lot of different as-Scripts for each pdf.
My main problem is the second error.
It would be really nice if someone had any good ideas.
Bye,
Stephan
The second error means that you need to pass the stage to the web view. Either pass it to mypdf class as parameter, or make mypdf DisplayObject (extend Sprite for example) and add it to stage.
I'm not sure this will solve your issue anyways - I think StageWebView can simply display html. The PDF is displayed in your browser because an external plugin for that is launched.
In AIR the situation seems different: http://sujitreddyg.wordpress.com/2008/01/04/rendering-pdf-content-in-adobe-air-application/
StageWebView is wont support for nativePath, instead of using this, you can try with pdf.url. And StageWebView also having support for open .pdf files.
public function mypdf(ActFile:String) {
MyWebView = new StageWebView();
file = ActualFile; //MARKING #1
pdf = File.applicationDirectory.resolvePath(file);
MyWebView.stage = stage; //MARKING #2
MyWebView.viewPort = new Rectangle (200, 200, 400, 400);
addChild( MyWebView );
MyWebView.loadURL(pdf.url);
}
Because, StageWebView will support file:/// format, but in nativePath we got C://.., so, this will help you. Or
Simply convert your StageWebView to Display object, and then added it to your container by using addElement().
You can convert it by,
var _view:SpriteVisualElement = new SpriteVisualElement();
_view.addChild( MyWebView);
this.addElement( view );
To test by, simply call this method in added_to_stage method to test if stage is having or not. This error will come if stage is not setted means also.

AS3: Scoping issue with -warn-scoping-change-in-this

I wanted to enable all compiler warnings in Flex to resolve them in my code. But there is one warning which I can't figure out how to solve it. Here is some example code:
package lib
{
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
public class player
{
private function tmp(event:NetStatusEvent):void
{
}
public function player():void
{
super();
var connection:NetConnection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, tmp);
}
}
}
On compiling with -warn-scoping-change-in-this I'm getting the following warning:
/var/www/test/src/lib/player.as(16): col: 59 Warning: Migration issue: Method tmp will behave differently in ActionScript 3.0 due to the change in scoping for the this keyword. See the entry for warning 1083 for additional information.
connection.addEventListener(NetStatusEvent.NET_STATUS, tmp);
Putting tmp as function inside player() will work but this is not what I want. I have even tried to use this.tmp as callback but there is no difference. Does somebody know how to solve this compiler warning?
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/compilerWarnings.html
This is a code migration warning. This warning is generated when a method of an object is used as a value, usually as a callback function. In ActionScript 2.0, functions are executed in the context they are called from. In ActionScript 3.0, functions are always executed in the context where they were defined. Thus, variable and method names are resolved to the class that the callback is part of, rather than relative to the context it is called from, as in the following example:
class a
{
var x;
function a() { x = 1; }
function b() { trace(x); }
}
var A:a = new a();
var f:Function = a.b; // warning triggered here
var x = 22;
f(); // prints 1 in ActionScript 3.0, 22 in ActionScript 2.0
That warning is only placed there to let you know that the behavior of your code might have changed in case you are migrating your code from AS2 to AS3 (which the compiler has no way of knowing beforehand). You should only enable the compiler option -warn-scoping-change-in-this when you are migrating your code from AS2 to AS3.
So, as I said in the comments, you shouldn't worry about that warning, since obviously seing your code that is not your case and you don't need that compiler option enabled.

AS3 Argument Error #1063 ... expected 1 got 0

So I got a very basic class
package {
import flash.display.MovieClip;
public class XmlLang extends MovieClip {
public function XmlLang(num:int) {
trace(num);
}
}
}
and an object at frame one:
var teste:XmlLang = new XmlLang(1);
I'm getting this error:
ArgumentError: Error #1063: Argument count mismatch on XmlLang(). Expected 1, got 0
What am I doing wrong?
Thank you very much for you help.
Something is up with your setup. I took your code and implemented it and it worked.
Here's what I did. I created a new test.fla file in AS3 and put the following code on frame 1 - no object on the stage, just code in frame 1.
import XmlLang;
var teste:XmlLang = new XmlLang(1);
stop();
Created a XmlLang.as file, copying your code exactly and saved it in the same folder as the test.fla. Compiled and got a trace of 1
So I'm not exactly sure what's going on. What version of Flash are you running?
Not sure if this was your case, but for future googlers: you get this error message when you're trying to initialize a vector but then forget the new keyword.
So this:
var something:Vector.<Something> = Vector.<Something>();
Will give you an error saying that Something had an argument count mismatch. The correct line is:
var something:Vector.<Something> = new Vector.<Something>();
Difficult error to get at a glance. Took me a few minutes to find it in my code, especially because it doesn't really give you the error line.
I expect you have an instance of XmlLang located on stage, that will be constructed using a constructor with 0 parameters, like an ordinary MovieClip. To check for this, change the constructor header to this:
public function XmlLang(num:int = 0) {
This way, if something will instantiate an XmlLang without a parameter supplied, the new instance will receive a 0 (the default value) as parameter. And then you check your trace output, I am expecting one or more zeroes appear, followed by an 1.

AS3 TypeError: Error #1009

I am trying to create a web application with multiple scenes, the error appears when I try to access the next scene with a button I created that contains multiple EventListeners for animation purposes.
The Button did bring me to the next scene, but the error still occurs. After tracing and debugging, the error seems to occur at the Mouse_Out event.
I am still very new to AS3, so can someone please explain to me where my code went wrong and if possible, correct the error for me or is there a better way of writting the code? Thanks in advance.
The Error Involved:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.transitions::Tween/setPosition()
at fl.transitions::Tween/set position()
at fl.transitions::Tween()
at Portfolio_fla::MainTimeline/about_btnOut()
My Code:
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
about_btn.buttonMode = true;
about_btn.mouseChildren = false;
about_btn.alpha = 0.3;
about_btn.addEventListener(MouseEvent.MOUSE_OVER, about_btnOver);
function about_btnOver(event:MouseEvent):void
{
var AboutAlphaOver:Tween = new Tween(about_btn,"alpha",Regular.easeIn,0.3,1,0.1,true);
}
about_btn.addEventListener(MouseEvent.MOUSE_OUT, about_btnOut);
function about_btnOut(event:MouseEvent):void
{
var AboutAlphaOut:Tween = new Tween(about_btn,"alpha",Regular.easeIn,1,0.3,0.1,true);
}
about_btn.addEventListener(MouseEvent.CLICK, about_btnClick);
function about_btnClick(event:MouseEvent):void
{
gotoAndPlay(1,"About");
}
Try to change your Tween code:
var AboutAlphaOut:Tween = new Tween(about_btn,"alpha",Regular.easeIn,1,0.3,0.1,true);
To:
var AboutAlphaOut:Tween = new Tween(event.currentTarget,"alpha",Regular.easeIn,1,0.3,0.1,true);
I'm not sure if it will work (I'm not too familiar with Flash IDE), but I think it's possible that you are getting error because other scene doesn't have a reference to a button. With event.currentTarget, you will search for reference in the event, so it should find it in any case.
BTW: You shouldn't name your variables starting by capital letter. That way you will more easily distinguish objects from classes.

How to use VGroup or HGroup in pure actionscript3?

I'm developing a flash app by using free Flex SDK and text editor and compiling in command line.
I want to use VGroup or HGroup in my actionscript to manage positions of DisplayObjects.
I wrote the following code:
import spark.components.*
import flash.text.*
var group:VGroup = new VGroup;
var text:TextField = new TextField
text.text = 'abc';
var sprite = new Sprite;
sprite.graphics.lineStyle(2, 0x000000);
sprite.graphics.drawRect(0, 0, 100, 100);
stage.addChild(group);
group.addElement(sprite); // runtime error
group.addElement(text); // compile error
But adding Sprite to VGroup causes runtime error:
TypeError: Error #1034: Type Coercion failed:
cannot convert flash.display::Sprite to mx.core.IVisualElement.
And adding TextField to VGroup causes compile error:
Error: Implicit coercion of a value of type flash.text:
TextField to an unrelated type mx.core:IVisualElement.
How to use VGroup or HGroup in pure AS3?
What is the difference between DisplayObject and IVisualElement?
UPDATE:
I tried the 1st way of www.Flextras.com's answer, SpriteVisualElement and StyleableTextField.
I wrote the following code:
package {
import flash.display.*
import spark.core.SpriteVisualElement
//import spark.components.supportClasses.StyleableTextField // compile error
import spark.components.VGroup
import flash.text.*
[SWF(backgroundColor=0xffffff, width=500, height=500, frameRate=12)]
public class VGroupTest extends Sprite {
function VGroupTest() {
//var text:StyleableTextField = new StyleableTextField
//text.text = 'abc';
var sprite1:SpriteVisualElement = new SpriteVisualElement;
sprite1.graphics.lineStyle(2, 0x000000);
sprite1.graphics.drawRect(0, 0, 100, 100);
sprite1.width = 200
sprite1.height = 200
var sprite2:SpriteVisualElement = new SpriteVisualElement;
sprite2.graphics.lineStyle(2, 0xff0000);
sprite2.graphics.drawRect(0, 0, 200, 200);
sprite2.width = 300
sprite2.height = 300
var group:VGroup = new VGroup;
group.gap = 10
group.width = 400
group.height = 400
this.stage.addChild(group);
// the following codes show nothing
//group.addElement(text);
group.addElement(sprite1);
group.addElement(sprite2);
// the following codes show 2 rectangles
//this.stage.addChild(sprite1)
//this.stage.addChild(sprite2)
}
}
}
But
import spark.components.supportClasses.StyleableTextField
caused the following error
40 Error: Definition spark.components.supportClasses:StyleableTextField could not be found
And no SpriteVisualElement is shown on the screen.
Am I missing something?
You're using the right conceptual approach. However, elements in a group (or VGroup or HGroup) must implement IVisualElement, which neither Sprite nor TextField implement.
You have a few options to consider:
Use a SpriteVisualElement instead of a Sprite; or use a StyleableTextField instead of a TextField.
Wrap up the Sprite or TextField as a child of UIComponent; then use that UIComponent as the element in the group.
Use MX Containers, such as HBox or VBox.
Use a UIComponent instead of a Group. You'll have to write your own layout code in updateDisplayList() for this to work.
My preference is the first approach, followed by the fourth approach. Approach 2 adds a lot of extra coding, and approach 3 is undesirable due to the dependency on the MX/Halo architecture.