Any Issues Between CS6 Flash Pro and Flash Builder 4.5? - actionscript-3

I am trying to follow this guide: http://tv.adobe.com/watch/learn-flash-professional-cs5/using-flash-pro-and-flash-builder-together/
While using CS6 Flash Pro and Flash Builder 4.5.
The issue I am having is my Flash Builder code doesn't seem to have any effect. I did everything the guide with the only variation being the names I used and button position.
The code I ended up with:
package
{
import flash.display.MovieClip;
import flash.text.TextField;
public class UntitledMessage extends MovieClip
{
public function UntitledMessage()
{
super();
var icon:btnDontKnow = new btnDontKnow();
icon.x = 0;
icon.y = 0;
addChild(icon);
var btnLabel:TextField = new TextField();
btnLabel.text = "Play Intro";
btnLabel.x = 250;
btnLabel.y = 275;
addChild(btnLabel);
}
}
}

If the source code seems to be ignored, try deliberately inserting a syntax error. Remove a curly brace or something similar.
If there are still no errors, are compiling from a .fla and this is supposed to be the root element, I would try checking the Document Class property in the .fla file. It's under Publish in the Properties tab in Flash CS6. It should state that UntitledMessage is the Document Class and the file has been found.
Also make sure you are editing the file that is actually being read and not a copy. Stupid but common mistake.

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 URLRequest Local File on multiple OS/Browsers

Greatings!
I have yet another question concerning the loading of a .swf inside a existing one.
In my game. I have a introduction screen in which I load another .swf (which is a movie).
This all works fine and the URLRequest is this:
request = new URLRequest("Movie.swf");
As I said, this works fine. However when I copy my game.swf and movie.swf to a USB stick.
(I put them in the same directory to prevent other issues).
It doesn't seem to find the movie.swf.
Now I know that it has to do with the path given in the URLRequest and/or the publish settings. But I do not know how to make this so that it searches in the same directory
as the game.swf is in.
I hope you guys have an answer for this issue.
Thanks in advance,
Matti.
Matti, I believe Lukasz's comment is correct about it being a security error.
You can avoid this security error by embedding Movie.swf instead of using a Loader. If you do this, then at compile-time the Movie.swf needs to sit next to the Game.as file, and it will be included in the Game.swf (no need to deliver both files, just Game.swf).
The syntax is:
package
{
import flash.display.Sprite;
public class Game extends Sprite
{
[Embed(source="MyMovie.swf")]
private var myMovieClass:Class;
private var myMovie:DisplayObject;
public function Game():void
{
myMovie = new myMovieClass();
// Technically myMovie is now a Loader, and once
// it's loaded, it'll have .content that's a
// MovieClipLoaderAsset, and .content.getChildAt(0)
// will be your MyMovie.swf main timeline.
}
}
}
Alternately, if you embed it as mimeType="application/octet-stream", you can get the bytes of the SWF and use it in your existing Loader's .loadBytes() method:
package
{
import flash.display.Sprite;
import flash.utils.ByteArray;
public class Game extends Sprite
{
[Embed(source="MyMovie.swf", mimeType="application/octet-stream")]
private var movieBytes:Class;
private var myMovie:DisplayObject;
public function Game():void
{
// Treat this loader the same as your current loader,
// but don't call .load(url), call loadbytes():
var l:Loader = new Loader();
l.loadBytes(new movieBytes() as ByteArray);
}
}
}

embedding a font in a swf using as3

I have a project using flash (and AIR for android and eventuall iOS) for translating some phrases. Although most fonts are fine there are some that I have to load after the user has chosen the languages. Over a year ago I generated a couple of swf files (Bengali and Urdu) and put them on my web server. The flash application then loads them when required and everything is OK...
However as I am nearing implementing the project I thought I should generate the swf files for the other languages that are in the pipeline and for some reason I can't manage it! Needless to say I have misplaced (tidied) the original AS3 source for the two fonts I have done.
package
{
import flash.display.Sprite;
import flash.events.Event;
public class ArabicF extends Sprite
{
[Embed(source = "trado.ttf",
fontName = "ArabicX",
fontFamily = "ArabicY",
fontWeight = "normal",
fontStyle = "normal",
mimeType = "application/x-font",
advancedAntiAliasing="true",
embedAsCFF="true")]
public static const ArabicZ:Class;
}
}
This has expanded from a much simpler form as I added things to get it to work and I must have tried all permutations of true and false. I load the swf ok but then can't extract the class. With the two fonts I embedded before the swf class and the parameter all have the same name and they work fine (i.e.
Urdu.swf
then later:
var FontClass:Class = evt.target.applicationDomain.getDefinition("Urdu") as Class;
and then
Font.registerFont(FontClass.Urdu);
in the calling .as application with the above Arabic.swf I try
trace("1 Arabic "+evt.target.applicationDomain.hasDefinition("ArabicF"));
trace("2 Arabic "+evt.target.applicationDomain.hasDefinition("Arabic"));
trace("3 ArabicX "+evt.target.applicationDomain.hasDefinition("ArabicX"));
trace("4 ArabicY "+evt.target.applicationDomain.hasDefinition("ArabicY"));
trace("5 ArabicZ "+evt.target.applicationDomain.hasDefinition("ArabicZ"));
but all return false
PS also tried generating the Arabic.swf using fontswf.bat which again seems to make a very similar swf file which is loaded but I can't extract the class from it
PPS I'm using flashdevelop and the font swf are set up as AS3 standard project compiler options.
I don't use Flash Develop, but perhaps I can offer some perspective from my implementation.
If I wanted to embed Arial, the embedding swf would "Export for ActionScript" the embedded font. In its document class, use registerFont() as below:
Font.registerFont(Arial);
Like every other swf, you'd use a Loader to import it into your runtime, and at that point, the font will be available to your global table. You can query the complete list of registered fonts using enumerateFonts().
var fontList:Array = Font.enumerateFonts();
for (var i:int = 0; i < fontList.length; i++) {
trace(fontList[i].fontName);
}
Assuming we've got a TextField called "txt", you can then implement that font with setTextFormat() like so:
var format:TextFormat = new TextFormat();
format.font = "Arial";
txt.embedFonts = true;
txt.antiAliasType = AntiAliasType.ADVANCED;
txt.setTextFormat(format);
txt.defaultTextFormat = format;
A disclaimer from Adobe on the use of these last two settings:
"When you apply a TextFormat object to a text field using the
TextField.defaultTextFormat property or the TextField.setTextFormat()
method, only its defined properties are applied. Use the
TextField.defaultTextFormat property to apply formatting BEFORE you
add text to the TextField, and the setTextFormat() method to add
formatting AFTER you add text to the TextField."
As I said before, my workflow doesn't utilize Flash Develop, but rather Flash IDE to embed the fonts into the swfs. Your results may vary, but be aware you must set embedFonts to true, or it won't respond to your embedded font. I've lost hair on that issue before.
Hope that helps. Cheers,
OK In case someone else runs into similar problems this is stage one of the answer (really the answer to my original question) still have to sort out how to get the font to be used in the flash.font.engine apparatus!
The critical parts are:
Point #1. the embedded font swf must have a name that doesn't clash with ANY name registered in the calling script. Bizzare and (as far as I could search) undocumented. i.e. I have a list of languages uploaded via xml services to an xml object and that includes for instance 'English' however the font loading doesn't work until I make the loadable font file into 'EnglishF.swf' The obvious choice of just 'English.swf' fails. So my embedded font source is now called EnglishF.swf and reads:
package
{
import flash.display.Sprite;
import flash.text.Font;
import flash.system.Security;
Security.allowDomain("*");
/**
* ...
* #author patrick
*/
public class EnglishF extends Sprite
{
[Embed(source = "Kingthings Exeter.ttf",
fontName = "EnglishF",
fontFamily = "EnglishF",
fontWeight = "normal",
fontStyle = "normal",
mimeType = "application/x-font",
advancedAntiAliasing="true",
embedAsCFF="true")]
public static var myFont:Class;
}
}
and the using script goes:
private function fontLoaded(evt:Event):void {
var FontClass:Class
if (evt.target.applicationDomain.hasDefinition(font1Name)) FontClass = evt.target.applicationDomain.getDefinition(font1Name) as Class;
else if (evt.target.applicationDomain.hasDefinition(font2Name)) FontClass = evt.target.applicationDomain.getDefinition(font2Name) as Class;
try {
Font.registerFont(FontClass.myFont);
trace("successfully loaded " + FontClass);
} catch (err:Error) {
trace("couldn't register font "+FontClass.myFont+" =>"+err);
}
}
The line in the embedded script about security is because of point #2: the registerFont doesn't work across domains. In fact the Security.allowDomain() didn't work and to debug this I have had to copy/paste the swf files on the PC and change the loader.load(URLRequest()) accordingly
There is still an issue that although the font is registered and claims to be compatible with the flash.text.engine TextElement requirements it still fails to be used as in:
_tl = new Array();
var block:TextBlock = new TextBlock();
var font:FontDescription = new FontDescription(fontName);
var formt:ElementFormat = new ElementFormat(font, fontSize);
//following gives 'true EnglishF'
trace(FontDescription.isFontCompatible(fontName,"normal","normal"), formt.fontDescription.fontName);
formt.color = colr;
var span:TextElement = new TextElement(text, formt);
block.content = span;
_tl[0] = null;
_tl[0] = block.createTextLine(null, width);
var tl:TextLine;
// after here justification and addition lines
I will post something if and when I sort out why this doesn't work (Unless some kind person does it for me!)

Im trying to write a program which loads external resources with metadata tags in As3

ive been given some work to do but i cant seem to understand why its not working..
I think im using a wrong approach,
Im trying to load a picture and a movieclip on the same stage..
Though ive managed to display a picture, but when i try to display a MovieClip.. There arent errors though when i run i get the following:
TypeError: Error #1034: Type Coercion failed: cannot convert LoadingFiles_MovingStars1#2aba161 to flash.display.Bitmap. at LoadingFiles()[C:\Users\user\Adobe Flash Builder 4.5\LoadingFiles\src\LoadingFiles.as:28
Here is the code,
package
{
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.display.StageScaleMode;
[SWF(width = "800", height = "600", frameRate = "30", backgroundColor="#FFFF00")]
public class LoadingFiles extends Sprite
{
[Embed(source="/../assets/Head.jpg")]
protected var MovingStars:Class;
[Embed(source="/../assets/water1.mp4", mimeType = "application/octet-stream")]
public var MovingStars1:Class;
public function LoadingFiles()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
// swf
var myStars:Bitmap = new MovingStars();
var myPic:Bitmap = new MovingStars1(); //
var yourPic:MovieClip = new MovingStars1();
myStars.x = (stage.stageWidth-myStars.width)/2;
myStars.y = (stage.stageHeight-myStars.height)/2;
addChild(myPic as MovieClip);
addChild(yourPic);
addChild(myStars);
}
}
}
Now ive written that code, but it doesnt work..
Im really stressing because im falling behind by a bit in class..
Help would greatly appreciated.
Thank you.
You're trying to instantiate an embedded .mp4 file as a Bitmap or a MovieClip. That's not possible, you need to create a video player or use an already existing videoplayer component.
Here's a more in-depth answer on that:
How to make an AS3 Flash video player?
When you embedded image
[Embed(source="/../assets/Head.jpg")]
protected var MovingStars:Class;
Your MovingStars is BitmapAsset class. This is class included in Flex SDK. So you need preload Flex SDK rsl's. Or configure Flex SDK libraries linking as merge in to code.
What IDE are you using?

classpath in as3 flashdevelop

I am very new in AS3. I use FlashDevelop 4. I have no Adobe Flash, just FD (pure AS3) I have problems with classpath. I searched the database but I found nothing that could help me. So the problem is as follow.
I have the project "Testing" in C:\AS App\Testing with the file Main.as. I have, also, the folder C:\AS App\W_T. In this folder is the file write_text.as. The file Main.as looks like that:
package
{
import flash.display.*;
import flash.text.TextField;
import flash.events.*;
import W_T.write_text;
public class Main extends Sprite
{
var t:TextField=new TextField();
public function Main():void
{
stage.addChild(t);
stage.addEventListener(MouseEvent.CLICK, write);
}
public function write(me:MouseEvent):void
{
var wt:W_T.write_text = new W_T.write_text();
t.x = 100;
t.y = 100;
t.text = wt.output();
}
}
}
The file write_text.as looks like that:
package W_T
{
import flash.display.*;
import flash.text.TextField;
import flash.events.*;
import W_T.*;
public class write_text
{
public function write_text()
{
}
public function output():String
{
var txt:String;
txt = "From function !";
return(txt);
}
}
}
I make the appropriate specification in the global classpath. But I get the following errors:
Error: Type was not found or was not a compile-time constant: write_text.
var wt:W_T.write_text = new W_T.write_text();
Error: Call to a possibly undefined method write_text.
var wt:W_T.write_text = new W_T.write_text();
Definition W_T:write_text could not be found.
import W_T.write_text;
Could you help me please to find where I have done wrong ?
Thank you.
EB
The problem is the compiler isn't finding your write_text.as file. By default, it will be looking here:
C:\AS App\Testing\W_T\write_text.as
Try adjusting accordingly and see if it works. When you declare package W_T { } flash will look in a subfolder called W_T for a file with the same name as the public class.
When you declare just simply package { } with no name, it will look in the root of your class library path, which seems to be a folder called Testing if that's where your main.as file is living.
If you wanted to use a common folder for your class files (that isn't nested in an individual projects folder), you can tell flash develop where to find them by going to: project -> properties, then the Classpaths tab. By default flash develop will only look in folders relative to the project.
The problem is that you haven't told the compiler (flex?) where to find the file. When you add it as classpath you only tell flash develop where to find the file, not the compiler.
First of all you have to check how you compile and secondly how you can change and add classpaths for your solution.u
I usually do this through ant script and a build.xml file and I can't unfortunately remember how the "pure as3"-projects are working in regards to compiling