Plugging Downloaded Actionscript3 Into a Personal Project - actionscript-3

I'm a total beginner to all of this.
I'm trying to make a three-second bit in a flash animation (not a game or interface--just a small sequence which uses a parallax star field I found on freeactionscript.com:
http://www.freeactionscript.com/2010/06/endless-starfield-parallax-scrolling/
I'm simply wanting to plug this code into an existing project. I have been digging for hours to find anything on the subject of plugging in AS3 codes, but all I can find are items which presuppose an advanced understanding of ActionScript, and don't really relate to my issue to boot..
The error I keep getting is "1120: Access of undefined property parallaxField." I believe I've placed all the files in the proper file structure, but it still won't render.
I'm not even sure where to begin looking to fix it, how to define the 'parallaxField' property, or how to attach it to the project I'm working on.
Please let me know if there's any other information you need to help, if you can..
Much appreciated!

in that link there is a demo example to download,
you have to have the com folder with the subfolder and file it it place,
then in your main js file import that in the com folder
import com.freeactionscript.ParallaxField;
then define the variable inside your main class
private var parallaxField:ParallaxField;
then inside your constructor function
// create container for our parallax effect
var mainContainer:MovieClip = new MovieClip();
addChild(mainContainer);
// instantiate parallax class
parallaxField = new ParallaxField();
// createField(container, x, y, width, height, numberOfStars, speedX, speedY);
parallaxField.createField(mainContainer, 10, 10, 530, 380, 100, 1, 1.5);

Related

Import Shapes of Custom Library from Draw.io in mxGraph

I'm currently working with the mxGraph library in javascript and I'm trying to create my own shapes in draw.io, to export them, then to reuse them as much as I want in my own program using the mxGraph library.
So far, I have tried to create a custom library, which contains all my shapes. I have exported it in XML which gives me a half-encoded XML file. Then, I'd like to import that mxLibrary in my own app so I can reuse these shapes for creating my own diagrams. I have no idea how to deal with that XML file.
I have also tried taking the XML from Extras -> Edit Diagram and reimport it with the codec, then with mxGraph#addCells but the shapes aren't grouped anymore, and I can't seem to find how to clone them.
My goal would literally to have my list of shapes/cells somewhere, which I can reuse whenever I want.
If this is not possible, how may I do that instead? I have also looked up how to create my own shapes (with redrawPath and the style thing), but it looks really long and boring.
Here's an example of what the XML looks like. The shape is a simple double square.
<mxlibrary>[{"xml":"xVNBbsIwEHyN78EugjOhcOqpLzDJgi05XstZSPJ7trFbiAqCqpV6sLQ7O2N7xrJQZdNvow7mDWtwQr0KVUZESlXTl+CckIWthVoLKQteQm7uTGfjtAg6gqdnBDIJTtodISEJaGlwGThEPIZMg0jQT46q0HuoSO8+6cX3K4zUfP4WsAGKA1M6W5NJjGVWGbAHQ1NMt/keX8qLHy6ypdv21GN7nbEE70FXH33HDyHUylDDO65nXOo2sD1u9rYH3nV1N4lrx/LfHL/8veO9da5Eh5Exjx5+GUIWzJNgmHRXAS1uBLT4eUDcXn7TOJt8tjM=","w":80,"h":80,"aspect":"fixed","title":"custom_shape_1"}]</mxlibrary>
Thank you in advance!
There are 2 ways I know, to do it, depending on your needs.
Embed draw.IO as an iframe in your app, and create a plugin that adds your own palette of icon on the side bar. you can watch the p1 plugin code, and replicate it plugin list in draw.io, look for the p1 plugin
. code example of how to integrate draw.io in your app
hint: if pulgins are not loaded, check the plugin folder link.
If you add the vertices on you own app, create your own style, and reuse it when creating.
updateStyles()
{
var style = new Object();
style[(<any>window).mxConstants.STYLE_SHAPE] =
(<any>window).mxConstants.SHAPE_IMAGE;
style[(<any>window).mxConstants.STYLE_PERIMETER] =
(<any>window).mxPerimeter.RectanglePerimeter;
style[(<any>window).mxConstants.STYLE_IMAGE] =
'../assets/transformer.png';
style[(<any>window).mxConstants.STYLE_FONTCOLOR] = '#000000';
style[(<any>window).mxConstants.STYLE_WHITE_SPACE] = 'wrap';
style[(<any>window).mxConstants.STYLE_VERTICAL_ALIGN] = 'bottom';
this.graph.getStylesheet().putCellStyle('transformer', style);
}
reuse this style whenever creating a vertex using insertVertex function.
try {
const parent = this.graph.getDefaultParent();
this.graph.getModel().beginUpdate();
const vertex = this.graph.insertVertex(parent, uuid.v4(), node, 40, 40, 80, 40, 'transformer');
} finally {
this.graph.getModel().endUpdate();
}

How to change bitmapdata in AS3

I'm building a spritesheet class. Hopefully this will be low hanging fruit to someone, but I'm stumped.
I have a spritesheet (.png) that I've loaded at runtime and placed a section of it on the stage using this code from within the Spritesheet class .as file ouside of the constructor method:
private function onLoad(e:Event):void
{
var loaderBmp:Bitmap = Bitmap(_loader.content);
_bmpData.copyPixels(loaderBmp.bitmapData, new Rectangle(0,0,80,80),new Point(0,0));
}
That works fine. I get my slice of the .png file displaying nicely. In my case, the spritesheet is meant for animating a character, so I need to update the BitmapData and I'm not having any luck. Here is what I'm trying this within my Main class in a function I use to alter the frame of the animation depending on the state of the character:
c._thisSpriteSheet._loader.content.bitmapData.copyPixels(loaderBmp.bitmapData, new Rectangle(0,20,50,30),new Point(0,0));
loaderBmp is a variable who's value is var loaderBmp: Bitmap = Bitmap(_spriteSheet._loader.content);
c is a reference to the Runner object that is the character.
_spriteSheet is a property of the Runner class of type Spritesheet.
_loader is a property of the c._spriteSheet and is the Loader object used when the spritesheet was instantiated.
It doesn't throw an error, but it also doesn't replace the original bitmapData object with the new one. I thought maybe this meant that I need to create a new BitmapData object and use that in the copyPixels method, but that returned the same results (nothing). When I step through the code in debug mode, everything looks like it is working, but my display object does not update with the new bitmapData. What am I tripping on?
Thanks for looking!
Well, probably no one will read this since I'm answering it so quickly, but I literally spent 3 days trying to figure this out. Sometimes trying to ask the question in a concise way helps one answer their own question, and moments later, voila!
So in case anyone has a similar issue, what I was doing wrong was that I was trying to access the BitmapData object via the Loader that originally loaded it. Then it dawned on me that I could simply reference the BitmapData directly via that property of the SpriteSheet class I had made. I think this will be pretty confusing for someone else to follow. If a moderator sees this and thinks it's junk, I don't mind it getting erased, but thought I'd keep it up anyway. The new code looked like this:
c._thisSpriteSheet._bmpDSheet.copyPixels(loaderBmp.bitmapData, new Rectangle(0,20,50,30),new Point(0,0));
and _bmpDSheet is the bitmapdata property of the class.

Actionscript 3 - Accessing a variable on the main timeline

I'm trying to make a file that is easy for a non-flash user to use/reuse to easily display content. The key here is that this file is to be a template for a novice user to just copy/paste some very minimal code to create different "flash card" type swf files.
The file I am creating has multiple buttons on the main timeline which when clicked, attaches a movie clip which will display a dynamic text area with content specific for the button that was clicked. The content for the text area will be loaded from a separate text file.
For the sake of this example, I'm just going to refer to one button...
So, on the main timeline, in frame 1, I have a variable definition:
var myFilename1:String = "mySampleFile2.txt";
When the button on the main timeline, in frame 1 is pressed, a movie clip is loaded which contains a text area. The content for the text area is located in that file: mySampleFile2.txt.
If I hard-code the file name, it works like a dream:
myTextLoader.load(new URLRequest("mySampleFile2.txt"));
But I don't want to hard code the file name. I want to refer the variable in the main timeline. In AS 2, it would have been
myTextLoader.load(new URLRequest(_root.myFilename1));
In AS3 I thought it would be either:
myTextLoader.load(new URLRequest(root.myFilename1));
OR
myTextLoader.load(new URLRequest(MovieClip(this.parent.root).myFilename1));
When I run the code I get the following error and when I run a trace I get the file name is NULL.
TypeError: Error #2007: Parameter url must be non-null.
How to I access the file name stored in the variable on the main timeline?
*************************** UPDATE! *************************
So I just discovered that the issue is related to a button on the screen. The button is one from the buttons library. If I remove the button, everything works great. But as soon as that button is on the main timeline, it makes it to I cannot access the variables using MovieClip(root).variable_name;. Unfortunately I want that button to trigger the events within the MovieClip. Any thoughts?
Not a good idea
You are not able to achieve your goals with this bad practice approach.
to use/reuse
The code you want to provide is not very reusable. It heavily relies on one variable existing in a certain place. Therefore it cannot be use twice in a project.
But I don't want to hard code the file name.
And now you are hard coding the variable and its location. If you considered hard coding the file name to be a bad things, consider this a bad thing, too.
What the problem is
Basically speaking, the problem is that your component is reaching out to grab this variable from somewhere within your project. But it is not the concern of the component to find the content it should display. It is not well encapsulated.
Learning from existing things
You want to display text. Let's take a look at the TextField class to see how it displays text.
var tf:TextField = new TextField();
tf.text = "hello";
addChild(tf);
As you can see, the text that it should display is passed to the TextField object. There is not some arbitrary variable one has to set in order to modify the text, as you are planning to do:
var tf:TextField = new TextField();
var someArbitraryVariableThatModifiesATextField = "hello";
addChild(tf);
There is no obvious connection to the TextField object and if there's a second TextField, this doesn't work at all.
Applying that to the problem at hand
Just like the TextField, your "flash card" should receive the file as a parameter. Either pass it to the constructor as seen in the example below, or create a method that takes it as a parameter.
var card:Card = new Card("mySampleFile2.txt");
addChild(card);
Additional thoughts
Create additional methods to set the values individually. There's nothing worse than some code that does exactly what one wants, but only operates on files and one doesn't have a file. The goal is again, to make it easy to reuse the code
Use the [Inspectable] meta tag to allow the user of your code to modify the properties at author time. This can be used to the extend of modifying properties belonging to a physics engine, now this is what I would call easy to use for a novice user.
Instead of writing code and thus requiring to recompile the file again, take the information (either the path to the file or it content) from the flashars that are passed to the .swf file when it is embedded into an html page. This makes the single .swf file truely reusable and easiest to use, because there's no As3 coding required whatsoever.
I haven't tested this but I believe the "root"-stage would be:
this.parent
In the child swf.
check out this question: as3 access variable from parent swf
Good luck!
Accessing variables or movieclips at main timeline is as following:
AS2:
_root.variable_name;
AS3:
MovieClip(root).variable_name;

Starling scaffold project showing blank texture

I am building an app using Starling and have imported the scaffold project however whenever I call getTextureAtlas() it doesn't show the image
this.mLogo = new Image(Assets.getAtlasTexture("powered_by_starling"));
this.mLogo.x = 0;
this.mLogo.y = 0;
this.addChild(this.mLogo);
There are no errors so I am guessing it can find the texture. If I change the name to something that doesn't exist it throws an error 'texture cannot be null'. I am also using
Assets.contentScaleFactor = Starling.current.contentScaleFactor;
and everything is pretty much a standard import of the scaffold as is however I am using Feathers UI screen navigator but I haven't had a blank image issue on other projects.
Edit: I can't seem to get the sprite to work within a class that extends feathers.controls.Screen
Is getAtlasTexture a function that you wrote? Are you using starlings asset manager? If that's the case, you will need a instance of that class, not static method call.
Anyway, try using the Texture class and the static method it offers. You don't need atlas(sprite sheet) for a Image - you will need it however for MovieClip.
Texture.fromBitmap
Texture.fromBitmapData
.... and others, check documentation
If your graphics are embedded, then use this:
var _img:Image = new Image(Texture.fromBitmap(new Assets.EmbeddedGraphic()));
Are you using atf? because the same happened to me until I used png and then it worked

How could I compile the code for this Flash tutorial?

I started reading this tutorial: http://active.tutsplus.com/tutorials/actionscript/creating-a-reusable-flash-uploader-with-actionscript-3-0-and-php/
I'm using FlashDevelop, and I pasted the full code into an ActionScript file. The errors I'm receiving are like this:
C:\Users\tempus\Documents\uploaderas\Uploader.as(30): col: 4 Error: Access of undefined property select_btn.
select_btn.addEventListener( MouseEvent.CLICK, browse );
^
C:\Users\tempus\Documents\uploaderas\Uploader.as(31): col: 4 Error: Access of undefined property progress_mc.
progress_mc.bar.scaleX = 0;
...
I understand that the errors appear because the objects have not been declared ( and they appear to be instantiated from somewhere ), but I don't understand how/what should I include to declare them. Could you point me towards a solution?
It's because the buttons are created in the Flash IDE (as the tutorial was meant to be compiled using the Flash IDE). Since the buttons don't exist in the code aspect you get that error.
You can either create the elements yourself via code, or use the Flash IDE and export a swc/swf of the neccessary UI elements and include that in your flashDevelop project. I'm assuming you'll want to do the latter -
in the Flash IDE, open the .fla, open the library panel, find the progress asset, right click it and bring up the properties. Check the "Export For ActionScript" option, then in the 'Class' field give it a unique name like "SelectBtn". Do the same for the 'progress' asset (only a different class name like 'ProgressBar'). Go to the flash publish settings, and on the flash tab select 'export swc'. publish the file and place the published swc in your flash Develop project folder (traditionally the lib folder of your project).
In Flash Develop, right click your swc and choose 'Add To Library'. (You may need to right-click again and go to options and choose the include completely option). Now you can access those classes you setup in Flash. Then in your code, declare and initialize the display assets:
public var select_btn:SelectBtn = new SelectBtn();
public var progress_mc:ProgressBar = new ProgressBar();
You'll also need to do that textField too. It would be easiest just to do it in your code though.
public var label_txt:TextField = new TextField();
Keep in mind you'll need to manually position and use addChild on all three elements this way. If you want to keep the positioning that's in flash, just select all the elements on the stage and press F8 to convert them to a MovieClip. Then in the library setup linkage the same as the others and give it a class name of something like "DisplayAssets" and export a new swc. Then your code would look like this:
public var select_btn:Sprite;
public var progress_mc:Sprite;
public function Uploader(){
var displayAssets:DisplayAssets = new DisplayAssets();
addChild(displayAssets);
select_btn = displayAssets.select_btn;
progress_mc = displayAssets.progress_mc;
//the rest of the code
}