embedded font displays no text (as3) - actionscript-3

using flash develop. so i downloaded "source sans" font from here: https://fonts.google.com/specimen/Source+Sans+Pro?selection.family=Source+Sans+Pro
it has a bunch of ttf files, "bold, italic, etc" im guessing i only need one, so i copied the regular one to my src folder, renamed it to "SourceSansPro", right clicked on my src folder and add new font library. i named it "SourceSansPro". and heres my code now:
main class:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
public class Main extends Sprite
{
private var format:TextFormat = new TextFormat("SourceSansPro");
private var text:TextField = new TextField;
public function Main()
{
text.embedFonts = true;
text.setTextFormat(format);
text.text = "abcdefg";
addChild(text);
}
}
}
the font library thing:
/**
Suggested workflow:
- create a fontLibrary subfolder in your project (NOT in /bin or /src)
- for example: /lib/fontLibrary
- copy font files in this location
- create a FontLibrary class in the same location
- one font library can contain several font classes (duplicate embed and registration code)
FlashDevelop QuickBuild options: (just press Ctrl+F8 to compile this library)
#mxmlc -o bin/SourceSansPro.swf -static-link-runtime-shared-libraries=true -noplay
*/
package
{
import flash.display.Sprite;
import flash.text.Font;
/**
* Font library
* #author 111
*/
public class SourceSansPro extends Sprite
{
/*
Common unicode ranges:
Uppercase : U+0020,U+0041-U+005A
Lowercase : U+0020,U+0061-U+007A
Numerals : U+0030-U+0039,U+002E
Punctuation : U+0020-U+002F,U+003A-U+0040,U+005B-U+0060,U+007B-U+007E
Basic Latin : U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E
Latin I : U+0020,U+00A1-U+00FF,U+2000-U+206F,U+20A0-U+20CF,U+2100-U+2183
Latin Ext. A: U+0100-U+01FF,U+2000-U+206F,U+20A0-U+20CF,U+2100-U+2183
Latin Ext. B: U+0180-U+024F,U+2000-U+206F,U+20A0-U+20CF,U+2100-U+2183
Greek : U+0374-U+03F2,U+1F00-U+1FFE,U+2000-U+206f,U+20A0-U+20CF,U+2100-U+2183
Cyrillic : U+0400-U+04CE,U+2000-U+206F,U+20A0-U+20CF,U+2100-U+2183
Armenian : U+0530-U+058F,U+FB13-U+FB17
Arabic : U+0600-U+06FF,U+FB50-U+FDFF,U+FE70-U+FEFF
Hebrew : U+05B0-U+05FF,U+FB1D-U+FB4F,U+2000-U+206f,U+20A0-U+20CF,U+2100-U+2183
About 'embedAsCFF' attribute:
- is Flex 4 only (comment out to target Flex 2-3)
- is 'true' by default, meaning the font is embedded for the new TextLayout engine only
- you must set explicitely to 'false' for use in regular TextFields
More information:
http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf69084-7f5f.html
*/
[Embed(source="SourceSansPro.ttf"
,fontFamily ='SourceSansPro'
,fontStyle ='normal' // normal|italic
,fontWeight ='normal' // normal|bold
,unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'
,embedAsCFF='false'
)]
public static const fontClass:Class;
public function SourceSansPro()
{
Font.registerFont(fontClass);
}
}
}
so in main, if text.embedFonts is false it will show the default font, if its true it will show up blank.
any help?
edit - new code
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.Font;
public class Main extends Sprite
{
private var format:TextFormat = new TextFormat("libel");
private var text:TextField = new TextField;
public function Main()
{
[Embed(source="libel.ttf"
,fontFamily ='libel'
,fontStyle ='normal' // normal|italic
,fontWeight ='normal' // normal|bold
,unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'
,embedAsCFF='false'
)]
Font.registerFont();
text.embedFonts = true;
text.setTextFormat(format);
text.text = "abcdefg";
addChild(text);
}
}
}

This is what you probably want.
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.Font;
public class Main extends Sprite
{
// After the [Embed] tag you need
// a variable definition it is linked to.
[Embed(source="libel.ttf", fontFamily='libel')]
private var Libel:Class;
public function Main()
{
// In order to share the font with the whole application,
// you need to provide its class to the method.
Font.registerFont(Libel);
var aFormat:TextFormat = new TextFormat;
aFormat.font = "libel";
// ... other format properties here.
var aField:TextField = new TextField;
// This way you will see that
// TextField even if fonts don't render.
aField.border = true;
// Setting the default text format is a good idea here.
aField.embedFonts = true;
aField.setTextFormat(aFormat);
aField.defaultTextFormat = aFormat;
aField.text = "abcdefg";
addChild(aField);
}
}
}

Related

Add your Stage in a ScrollWindow ActionScript 3.0

I'm gonna try explaining my situation with images, to make sure that everyone will understand what i want to succeed.
First of all i have 3 files:
GenImage.fla which is linked to class GeneralImage.as
and it only contains the following picture (I tried to make the image Movie Clip but again it's not working):
Pic1
and a file named ScrollUI.as which contains the class ScrollUI.
What i want to succeed is from my GeneralImage class to create a ScrollUi item, pass the stage, and there create a ScrollPane which makes the picture look like this:
Pic2
The center part of the second image is the ScrollPane Component, which i need to make it Scrollable through the whole image. I managed to get it in my screen but i can't put the Stage in it and make it scrollable.
These are my codes :
GeneralImage.as
package {
import flash.display.*;
import flash.events.*;
import flash.display.Stage;
import ScrollUI;
public class GeneralImage extends MovieClip
{
public function GeneralImage()
{
var k = new ScrollUI();
k.ScrollConstructor(this);
}
}
}
ScrollUI.as
package
{
import flash.display.*;
import flash.events.*;
import fl.containers.ScrollPane;
import fl.events.ScrollEvent;
import fl.controls.ScrollPolicy;
public class ScrollUI extends MovieClip
{
private var _mainStage:Stage;
var aBox:MovieClip = new MovieClip();
var aSp:ScrollPane = new ScrollPane();
public function ScrollUI()
{
}
function ScrollConstructor(stage:Object):void
{
_mainStage = (stage as MovieClip).stage;
aBox == stage as MovieClip;
aSp.source == aBox ;
_mainStage.addChild(aBox);
aSp.setSize(300,300);
aSp.move(150, 75);
aSp.scrollDrag = true;
aSp.horizontalScrollPolicy=ScrollPolicy.OFF;
_mainStage.addChild(aSp);
}
}
}
So what i want it to set the Source of the Scroll Pane ( which is named aSp ) to be the _mainStage which is the stage i get from GeneralImage
Your issues is likely these two lines:
aBox == stage as MovieClip;
aSp.source == aBox ;
You're doing a comparison by using two ==, which effectively does nothing in your case. Use a single = to assign a value.
This is how I would suggest you approach this:
In the FlashPro library, find your image asset (I'm going to assume you have it wrapped in a MovieClip), right-click (or command click) and go to it's properties. Check the "export for actionscript" box, and give it a meaningful class name (for my example, I'll assume you called it MyImage)
Then you could do the following:
ScrollUI Class
package
{
import flash.display.Sprite;
import fl.containers.ScrollPane;
import fl.events.ScrollEvent;
import fl.controls.ScrollPolicy;
public class ScrollUI extends Sprite
{
//just declare the variables here, don't assign them new values
private var aBox:MovieClip;
private var aSp:ScrollPane;
public function ScrollUI()
{
//use the actual constructor...
aSp = new ScrollPane(); //instantiate a new scroll pane
addChild(aSp); //add the scroll pane to the display
aBox = new MyImage(); //instantiate an new MyImage from the library
//set the scroll pane properties
aSp.source = aBox; //you had two = signs here before, which doesn't actually assign anything it compares
aSp.setSize(300,300);
aSp.move(150, 75);
aSp.scrollDrag = true;
aSp.horizontalScrollPolicy=ScrollPolicy.OFF;
}
}
}
Document Class
package {
import ScrollUI;
public class GeneralImage extends MovieClip
{
public function GeneralImage()
{
var k:ScrollUI = new ScrollUI(); //create a new instance of the ScrollUI class
addChild(k); //add the scrollUI object to the display;
//OR, you just do this:
//addChild(new ScrollUI());
}
}
}
You could also just set the .source property of the scroll pane to the physical path of your image.
I found the solution, Thanks Batman for his help, I changes some things into my code and the program is working.
First of all as Batman said , In my GenImage.fla i made the logo a MovieClip and i named it "wholemap"
Here are my codes :
GeneralImage.as
package {
import flash.display.*;
import flash.events.*;
import flash.display.Stage;
import ScrollUI;
public class GeneralImage extends MovieClip
{
//as Batman indicated, I should have used the ScrollUI constructor, but
//except for the Stage, i also send the wholemap that is in my GenImage.fla
//<< this.getChildByName("wholemap") as MovieClip) >>
public function GeneralImage()
{
var k = new ScrollUI(this, this.getChildByName("wholemap") as MovieClip);
}
}
}
ScrollUI.as
package
{
import flash.display.*;
import flash.events.*;
import fl.containers.ScrollPane;
import fl.events.ScrollEvent;
import fl.controls.ScrollPolicy;
public class ScrollUI extends MovieClip
{
private var _mainStage:Stage;
var aBox:MovieClip = new MovieClip();
//So our constructor gets 2 items, a Stage, and a MovieClip
public function ScrollUI(stage:Object, pic:MovieClip)
{
//We set the Stage at the variable _mainStage with that way:
_mainStage = (stage as MovieClip).stage;
//We set the Image that we will take at our clip variable :
var clip:MovieClip = pic;
//And we send the Movieclip (clip) in our ScrollConstructor function
ScrollConstructor(clip);
}
function ScrollConstructor(Clip:MovieClip):void
{
var aSp:ScrollPane = new ScrollPane();
aBox = Clip;
_mainStage.addChild(aBox);
aSp.source = aBox ;
aSp.setSize(300,300);
aSp.move(150, 75);
aSp.scrollDrag = true;
aSp.horizontalScrollPolicy=ScrollPolicy.OFF;
aSp.verticalScrollPolicy=ScrollPolicy.OFF;
_mainStage.addChild(aSp);
}
}
}
Thank you very much for your assistance, I hope if someone else come across with this problem to be able to solve it with this Answer

Flash Develop warning : Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex

My code is : when i write tweenline flashdevelop closes . moreover it showed many times "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex" this warning .
package
{
import com.greensock.layout.AlignMode;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.LoaderInfo;
import flash.net.navigateToURL;
import flash.display.DisplayObject;
import com.greensock.TweenLite;
import com.greensock.easing.Circ;
public class Main extends MovieClip
{
public var BgMC:MovieClip;
public var logoMC:MovieClip;
public var bannerWidthArray:Array = [550];
public var bannerHeightArray:Array = [400];
public var loopcount:Number=0;
public var loop:Number=2;
public function Main() :void
{
if (stage) init ();
else addEventListener(Event.ADDED_TO_STAGE , init);
}
private function init (e:Event=null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
startbanner ();
}
private function startbanner (): void
{
BgMC = new bg_mc();
logoMC = new logo_mc();
BgMC.x = 0;
BgMC.y = 0;
addChild(BgMC);
logoMC.x = 20;
logoMC.y = 10;
addChild(logoMC);
initAnimation ();
}
private function initAnimation () : void
{
BgMC.alpha = 10;
logoMC.alpha = 10;
// ? Weird
Tweenlite(
}
}
}
Seeing the first version of your question, I understand that your are speaking about a FlashDevelop .Net error and not a ActionScript one, so try to find a solution in the FlashDevelop forum.
yes. i have found the exact answer for you . it happed for me . Because Everybody thinks that his/her windows is Program Files (x64) but that's not . you are running C:\Program Files (x86) . that's why you need to install another Jdk.
just go to jdk download website and you will see that they have different jdk for Program Files (x86) . http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Download it what exactly you are running in C:\Program Files (x86) .and your many kinds of problem related like this is solved

Passing a variable between classes

I am trying to pass a variable "budget" from my DocumentClass of a flash file, to a class.
Currently I have :
(DocumentClassv5 , this is the code thats attached to the flash file in the properties panel, some code ommited)
package
{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.*;
import flash.ui.Keyboard;
import flash.display.Stage;
import flash.text.TextFieldType;
import flash.media.Sound;
import flash.media.SoundChannel;
import miniGameOne;
import floorTileMC;
import flash.display.Loader;
import flash.net.URLRequest;
public class DocumentClassv5 extends MovieClip
{
/*#################################
## Defining Variables ##
#################################*/
public var budget:int = 0;
var gameOne:miniGameOne = new miniGameOne();
/*#################################
## Constructor ##
#################################*/
public function DocumentClassv5()
{
/*#################################
## Adding Event Listeners ##
#################################*/
trace("Document class loaded");
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*###################################################
## Begins the mini game ##
###################################################*/
public function begin(evt: MouseEvent)
{
beginGame.visible = false;
beginGame.removeEventListener(MouseEvent.CLICK, begin);
budget = 500;
cleanListeners();
gameOne.loadGame();
trace(gameOne.testVar);
trace(floorTile.testVar2);
/*#################################
## Adding Event Listeners ##
#################################*/
trace("Game started");
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
Then I have the miniGameOne class file, which at the moment does nothing
I also have another class file, called tileFloorMC. This is attached to a symbol.
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import DocumentClassv5;
public class floorTileMC extends MovieClip
{
var propertyA:Number;
//var hackerClass:DocumentClassv5 = new DocumentClassv5;
public var testVar2:int = 50;
public function floorTileMC()
{
this.propertyA = randomRange(100, 500);
this.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);
this.addEventListener(MouseEvent.ROLL_OUT, manageMouseOut, false, 0, true);
}
private function manageMouseOver(evt: MouseEvent)
{
this.gotoAndStop(2);
//trace(mainClass.budget);
}
private function manageMouseOut(evt: MouseEvent)
{
this.gotoAndStop(1);
//mainClass.budget += 1;
}
private function randomRange(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
}
}
Now, essentially I will need to be able to pass budget from DocumentClassv5 TO floorTileMC, and then BACK to DocumentClassv5. At the moment, I can pass anything from floorTileMC and anything from miniGameOne into DocumentClassv5, but when i try and pass from floorTileMC to DocumentClassv5, I get error
Error #2136: The SWF file file:///yadayada/GameV5.swf contains invalid data.
More specifically, as soon as I uncomment //var hackerClass:DocumentClassv5 = new DocumentClassv5;
Any help would be greatly appreciated!
Thanks,
Tiffany
You're trying to instantiate your document class in a subclass:
var hackerClass:DocumentClassv5 = new DocumentClassv5();
You want access to access the existing instance, not create a new one.
One thing you can do, is create a static reference to your document class. (see code sample below)
Static references can get ugly though, and you may just want to pass a reference of your doc class to your other classes when you instantiate them.
Both method below:
In your document class:
//instead of the line below:
var gameOne:miniGameOne = new miniGameOne(); //It's a bad idea to instantiate non primitive objects before the constructor of your document class runs.
//just declare it, and instantiate it in the constructor
var gameOne:miniGameOne;
//if you want to use a static reference:
public static var me:DocumentClassv5;
public function DocumentClassv5()
{
/*#################################
## Adding Event Listeners ##
#################################*/
//if using the static var me, set it's value to this (the instance of the document class):
me = this;
trace("Document class loaded");
gameOne = new miniGameOne(this); //pass a reference to the document class if NOT using the static var me
}
If using the static var me, you access it by doing the following from any class:
DocumentClassV5.me.budget;
Another cleaner alternative (if the values you need access to aren't really directly tied to any class, eg. global preferences), is make a whole new class that is just static (doesn't get instantiated) to hold your preferences.
package {
public class Global {
public static var budget:Number = 50;
}
}
Then you'd access budget by importing your Global class and doing Global.budget = 5

Add a movieclip on a 3d cube and have interaction with it

I created a rotating cube using the below code and add bitmaps as sides of the cube.
I was wondering if it's possibly to assign movie clips as sides of the cube so I can have some interaction with them.
import flash.events.Event;
import flash.display.Bitmap;
import flash.display.BitmapData;
import org.papervision3d.cameras.CameraType;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.view.BasicView;
var cube : Cube;
var basicview : BasicView = new BasicView(640, 480, true, false, CameraType.FREE);
addChild(basicview);
var logo : Logo = new Logo( 0,0); //Bitmapdata (jpeg) exported as class Logo from library
var matFront : BitmapMaterial = new BitmapMaterial(logo);
var matBack : BitmapMaterial = new BitmapMaterial(logo);
var ml : MaterialsList = new MaterialsList();
ml.addMaterial(matFront, "front");
ml.addMaterial(matBack, "back");
ml.addMaterial(new ColorMaterial(0x551F92),"right");
ml.addMaterial(new ColorMaterial(0x431872),"bottom");
ml.addMaterial(new ColorMaterial(0x341359),"top");
ml.addMaterial(new ColorMaterial(0x7429C7),"left");
cube = new Cube(ml,200,200,200,5,5,5);
basicview.scene.addChild(cube);
basicview.camera.fov = 20;
addEventListener(Event.ENTER_FRAME, enterFrame);
function enterFrame(e:Event) : void
{
cube.yaw((320-mouseX)*0.01);
cube.pitch((240-mouseY)*0.01);
}
basicview.singleRender();
}
UPDATE
I add this
var matFront : MovieMaterial = new MovieMaterial(new MV(),false,true);
matFront.interactive = true ;
MV is just a square with this code
package Scripts {
import flash.display.MovieClip;
import flash.events.*;
public class MV extends MovieClip
{
public function MV( )
{
buttonMode = true;
addEventListener(MouseEvent.CLICK,traceFunction);
}
private function traceFunction(ev:MouseEvent) {
trace("clicked");
}
}
}
Why I have not any interaction when I click the side with the movie clip?
UPDATE 2
Ok I find it
I had to add this line
basicview.viewport.interactive = true;
But why I have interaction even when the side of the movieclip isn't visible.
How can I avoid it?
Yes it is possible, you have to create Materials from the MovieClips you want to use, to do just that take a look at the classes MovieMaterial and MovieAssetMaterial inside the papervision3d materials Package.

ActionScript play audio

I am just trying to make a simple .swf file that plays a piece of audio when it loads. This compiles but when I bring it up into the browser nothing happens. I could only find sprite based tutorials so I took a stab that you can extend Sound the same way as you would extend Sprite. The final version is going to be headless and called my Java Script to play audio on Events.
package {
import flash.media.Sound;
import flash.net.URLRequest;
public class typeRight extends Sound {
public function HelloWorld( ) {
load(new URLRequest('./sound.mp3'));
play();
}
}
}
I am NOT working in Flash so please no GUI advice ; )
Rather than subclassing the Sound class, create a document class like this that contains a Sound class in it:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
public class SoundPlayer extends Sprite
{
protected var _sound : Sound;
protected var _channel : SoundChannel;
public function SoundPlayer()
{
_sound = new Sound();
_sound.addEventListener(Event.COMPLETE, soundLoadCompleteHandler);
_sound.addEventListener(IOErrorEvent.IO_ERROR, loadError);
_sound.load(new URLRequest("./sound.mp3"));
}
protected function soundLoadCompleteHandler(evt : Event) : void
{
// Use the _channel object to control sound properties such as pan and volume.
_channel = _sound.play();
}
protected function loadError(evt : IOErrorEvent) : void
{
trace ("ERROR :: " + evt);
// You could try recovering from the error here.
}
}
}