i have this apps: http://www.jungle-g.co.il/#/System/
Currently, when a user selects a product (eg shirt) He can make only one side of the shirt.
When the user wants to edit another side of the shirt, he will have to complete the booking of the first side and then invite the other side.
My problem is I can not find how to save the first image in the flash memory or in movieclipe.
My interview is to create a movieclip one for each side user edits only when the user decides to do the actual booking send all the pictures from the movieclip.
Is this possible? If not is there another way?
I did research on the topic and found no solution that I could use it.
I found the website: http://code.google.com/p/swfupload/
But I did not understand how it helps me in my case.
Thank you to all the helpers, I break my head for over a month on the case.
You can create a class to hold statics of your bitmapData.
package {
public class ShirtState
{
public static var ShirtFront:BitmapData;
public static var ShirtBack:BitmapData;
}
}
Say you have a shirt that you're editing one side of.
var shirtFront:MovieClip; //this is the shirt you are working with.
once you are done
var shirtFrontBitmap:Bitmap = new Bitmap(shirtFront.width, shirtFront.height);
shirtFrontBitmap.draw(shirtFront);
once you have the bitmap you can save it to your static class
ShirtState.shirtFront = shirtFrontBitmap.bitmapData;
you can then access it anytime in your app provided you don't reload it.
There are some caveats:
If you have a module application where individual swfs are loaded and unloaded by the DOM then you may want to use a LocalSharedObject to store your images. To do that you will have to convert the bitmap data to Base64 (I would anyways) and then store taht string in the local share object. Be mindful that object has a max file size (not sure what it is).
You don't necessarily have to store bitmaps of your shirt sides. You could create your application to create a Class for shirt and as long as an instance of it exists you can have access to both sides of the shirt.
I am not sure how you are building this app, but generally you wouldn't even need to use a static if everything is in the same context. The actual service call to deliver both sides of the shirt to a server for processing would be made at the absolute end.
Related
So I'm new to coding as a whole and though I've messed a little with AS before I'm at an absolute loss. I've been using a pretty helpful website that gives a step-by-step on making a platformer/sidescroller, but one of the key things I want to include in my game is the ability to swap between two characters- i.e., if the player hit space or any other key, you could swap out to the other character (with different abilities and all).
My game only really has one big stage, and it's nothing complicated at all (it's something I'm trying to get done in about a little over 24 hours) which is why I decided not to make the character change for each "level"- because there's only one big one. I want the player to be able to decide when they want to play whichever character they fancy, but I have no idea how to go about it.
Uh, and if it helps clarify anything, I basically tried to follow that tutorial site as closely as I could without copying source code.
Thanks so much for taking the time.
You need to do a thing named "separate graphics from code". The tutorial says "convert your player to a Movie Clip Symbol ... create new Player(), add it to stage", then it teaches about how to control the player. You need to split your Player class into two, one remains as Player and contains code, the other is a skin class, barely a MovieClip without code. In your Player class you need to make a method to operate skins, the interface is up to you, I suggest a string lookup of a skin class, then you can tell your player to change skins both at costruction time and probably at runtime. An example:
public static const SKIN_DEFAULT:String="default";
public static const SKIN_RED:String="red";
public static const SKIN_BLUE:String="blue";
private static var SKINS:Object={
SKIN_DEFAULT:DefaultFace;
SKIN_RED:RedFace;
SKIN_BLUE:BlueFace;
}
Here, SKINS is a lookup object with keys as strings and value as Class references, these are the MovieClip symbol names an example expects to exist. Say you want a gray blob, a red angry face and a blue smiley save to be available, you name them DefaultFace, RedFace, BlueFace and put these names into this lookup object. Then, you need to make your player change skins. It's pretty easy once you get the drill.
public class Player extends Sprite {
// Sprite should do, as Player is now code-only
private var skin:MovieClip; // this will hold our player's skin
public function setSkin(newSkin:String):void {
// call this to change the skin
var newSkin:Class=SKINS[newSkin] as Class;
if (newSkin==null) return; // sanity check
if (skin) if (skin is newSkin) return;
// ^ changing skin for the same? We're that skin already!
if (skin) if (contains(skin)) removeChild(skin); // remove old skin
skin=new newSkin(); // create a new skin object
addChild(skin); // make it attached to the player
} // we're done!
// rest of code here
}
Make sure that your Player will at least put on default skin when created, or else you won't be able to see player move.
In order to trigger skin change, you can create an array of buttons, up to making them out of all possible SKINS (for this, either expose SKINS variable by declaring it public instead of private as it's now, or provide another means to get the list of classes), which will call player.setSkin() with a correct parameter.
I have been writing a game in timeline code. I want the different frames (rooms) in the game to be able to share information between each other. Of course, timeline code is limited to the frame it is written in.
After doing quite a bit of reading ("Foundation Game Design with Flash" and a number of articles, tutorials, forums etc) I decided to employ a document class. This did not work either. It seems it only works for frame one but not the rest of the frames (I have four).
How can I have frame four respond to something that happpened in frame one? For example, if the player achieves something in frame one, I want a movie clip in frame four to be visible.
If You are writing your code on the timeline, My suggestion would be to create two layers in the timeline, one for 'frame-actions' - in this layer you insert the code specific to a single frame (will work when the movieclip is stopped on that particular frame).. And also create one more layer called global-actions (for the entire timeline). Only the first frame will be a key frame and there should be empty frames till the end of the timeline.
In this layer actions write the code that you want to access from any keyframe in the same timeline.
If you define a variable in the actions which are written for the whole timeline (global-actions) then that will be available on all the frames.
Now if you want to go to a different frame based on some action, just write some functions in the layer which contains global actions and call that particular function through the frame actions. To go to a different frame use the 'gotoAndStop(frameNumber)' function of flash.
I want to tell you that while it will work, I would not recommend using it in this way.
HTH.
You can use static variables - these are variables which are linked to a class, rather than an instance of it.
Suppose your document class was called Document.as, and you wanted a variable, playerLives, to be visible from any part of the program.
Declare it inside Document.as:
public static var playerLives:int = 3;
You can then reference this directly from anywhere else in your code with:
Document.playerLives
(note that the variable is a member of the class itself, not an instance of it).
You could use a dedicated Statics class to hold these variables if you want to keep your document neat, or attach them to the relevant classes (eg Player.lives)
I've not used timeline/frames for some years but I believe this is how I used to do it!
NB Statics will be fine for your purposes but they are, in some ways, an equivalent to the _global variable in AS2 (at least, they can be used in the same manner) - many would not approve of their use, or over-use, as they are freely accessible from anywhere in your program (thus anathema to the OO concept of encapsulation), but personally I try not to worry about it in small cases - the most important thing to know about the rules of any design pattern is when they can be broken!
They are also slightly slower to access than instance members, but you won't notice this unless you are constantly accessing/changing them (making things like player velocity, which will need to be referenced/changed every frame, static, is not a good idea).
Hope this helps.
You may find the simplest way to link everything with the document class is to move your four frames into a movieclip together and have that on the first frame, then interact with that movieclip.
E.g. in the document class, where the movieclip instance on the timeline is called 'game'.
game.gotoAndStop(4);
game.objectToDisplay.visible = true;
If you encounter reference errors in the IDE then you can avoid these by using [] notation to refer to the properties of game, e.g. game["objectToDisplay"].visible = true;
Note that it's not really best practice to do this, but it will at least help you to finish that first game which is really more important at this stage in your learning. Afterwards, if you want to learn more then I'd recommend "The Essential Guide to Flash Games" by Jeff Fulton from 8bitrocket.com - it will teach you how to use the document class effectively.
I have a menu with five buttons. Menu is visible all the time. there is click event for each menu item. which slides corresponding movie clip from left to right. each movie clip has different nature events and respective animation and activity. for example tab 1 brings the video page. and within that movie clip I have video events like play pause volume and on complete etc. events and code. tab 2 has button group for Time and another button group Features. depending on user selection code will calculate and show value on a animated counter. tab 3 has button group for Time and button group Source. as per the user selection it will calculate and show the values as animated graph. and so on.
Right now I have all the individual tab movie clip has its own time line code for its own events. and some crossover variables and references with other tabs. Everything is working as expected. No problem. I know time line code is not the best way to do any complex project.
So, I would like to get the entire coding as one class or more classes if that is the correct way.
I am beginner as far as class logic. I have already created Main as document class and could control the general navigation of tabs and their initial look. But stuck at tab specific button events and other such unique events for the specific tab.
Any help is greatly appreciated. Thanks in advance.
any similar example or suggestions.
First of all, thanks a lot for a prompt response. It seems like I am not even a beginner. I need to read a lot and probalbly grasp all fundamental concepts thoroughly. I have gone through both the links suggested in your comments. I am trying to digest the stuff slowly. I do not have any formal informal education regarding OOP or any sort of programming. To be honest, I have hard time understanding the code you have suggeted. Not because of your code but because of my level of caliber. I will have to spend some time to make myself clearer regarding events and sequence etc. different tab contents are as movieclips to main timeline and already placed on stage. It comes and goes to its corresponding tab button click event. I am not marking your answer as yes because I still need to my own homework based on your suggestion. Thanks a lot once again. I am sure I will ask few more questions later.
This is how I would design it:
I'd have a Menu Class, which only contains the buttons and "converts" clicks on them into more specific events. That might look something like this:
public Class Menu extends Sprite {
protected var buttons:Vector. = new Vector.();
public function Menu() {
super();
var loops:int = numChildren;
for (var i:int=0; i<loops; i++) {
var button:SimpleButton = getChildAt(i) as SimpleButton;
if (button) {
buttons[buttons.length] = button;
button.addEventListener(MouseEvent.CLICK, broadcastMenuEvent);
}
}
}
public function broadcastMenuEvent(e:Event):void {
var button:DisplayObject = e.currentTarget as DisplayObject;
dispatchEvent(new Event(button.name, true));//bubbling, can catch at any level
}
}
The way this is built, you can change the events that are being dispatched simply by changing the name you give the instance of the button on stage. Note that you need to apply Menu as the Base Class and not the Class for this to work if you have "declare instances automatically" unchecked, because doing it that way allows the compiler to generate those instance names for you in a way your base Class doesn't have to know about.
At this point, you can then deal with those events in another place--whether it's your main document Class or whether you have a separate Controller.
I would define each of the Views you described as a separate Class as well. If you have objects coming and going on the stage, you can use one of the techniques described here to handle that. Otherwise, it's fairly straightforward to address your timeline instances from the base Class instead of timeline code. Again, you can listen for those events in the main document Class or a dedicated Controller--the main point is to make sure your Views are not making any important decisions and usually they should not be editing data.
You can choose to have your Main Document orchestrate how the tabs get added and removed (I'm a big fan of using the timeline with goToAndStop, but not everyone shares this preference), or, again, you can separate this logic out to a dedicated Controller. I would suggest that if it's possible to generalize how your Views work to have them implement a single Interface. That way, you can give them a single instance name and manage them all with the same getter/setter pair (assuming you go the timeline route).
Note the Flash compiler isn't terribly sophisticated in this regard, so if you do this and your Views extend different parent Classes, you'll get compiler warnings. Just ignore these--they don't mean anything.
The thing you shoud try to root out of your code completely is the part where Views are referencing each other. The only time it's acceptable for one View to know about another is when it's a parent knowing about its child. Even then, try to have as little specific knowledge as possible. Notice in the Menu View I wrote as an example, the parent only knows there may be some SimpleButtons, but it has no specific knowledge of where they are on stage, what, specifically, is in them, or even what there instance names are.
Instead of having your Views know about one another, have a third party (which, again, you can choose to use the main Document Class for or not) that transfers requests for state changes (in the form of events) from one to another.
I have a flash assignment that I need help getting started, any advice would be greatly appreciated. The assignment is to create an application for playing a card game, I have to create an MXML component that has two variables, one variable stores the image of the back of a playing card, the other variable has t store all 52 options of a front facing card (the second variable will store over 50 images).
I've written the variable for the back of the card image like this:
public var backOfCard:Image = new Image();
backofCard.source = 'asset/backImage';
However I get an undefined variable error (1120: Access of undefined propery variable img1), I feel like there's something small that I'm missing here, but I was wondering if anyone could spot it.
I'd also like to know if I should use the same method for each jpg image for the front of the cards, it seems like it would be a lot of repetitive code aside from the change in filename for the front of the card images.
Here's a snippet of the homework assignment, again I just need help getting this part correct, I really appreciate any help with this.
Your job is to supply the custom component named Card. Create the
component by using File → New → MXML Component. In the popup dialog
box
leave the Package blank
Name the component Card
Base Card on spark.components.Image
What goes into the Card component?
For each card, we'll want to be able to show the front face of the
card, or its back face. That means each card should have a place to
store information about what file to show as its front face, and what
file to show as its back face.
To do this, create two variables in the Card component to store the
file names. You might call these variables backImage and frontImage.
Your access modifier is what's bothering me.
If you're creating these definitions in your class file, then the first statement works:
public var backOfCard:Image = new Image();
But if you're in one of the methods, usually the constructor (sometimes called the ctor), or any other method of the application, you could use the 2nd statement:
backofCard.source = 'asset/backImage';
But the combination of both is what I think is confusing. Because the "access modifier" (i.e. public, private, internal, protected) is what you use to define variables and methods within a class. And since you're putting both side-by-side (a definition and an assignment statement), I think you're mixing when to declare them.
I am putting together a Flash game (using Flixel) and I have a lot of sprites whose images (.png format, mostly) I need to include in my game. I'm used to using code like:
[Embed(source = "../../lib/ship-0001.png")]private var _ship0001Sprite:Class;
in order to include an image file. Is there a way I can do this other than embed? I'd like to use a for loop if possible, grabbing every needed file by number. This way instead if having several lines for each ship type (to grab its sprite, icon, store view, etc), I can just change a variable (eg NUM_SHIP_TYPES) and add the files by number for the new ship.
Is embed the only way to do this where the files are included in the .swf, or is there another way I can do this? Or is there a way I can use a for loop with embed?
This may not be a popular answer. But it depends on preferences. I'm not trying to start a best practices discussion, just listing a possibility.
If you have multiple images for each ship. And its the same number of images per each ships then the below could be a possibility. Of not, then completely ignore what I suggest.
Have a folder for each one of your ship types and then a class file within that folder and place your images within that folder along side the class files..
package shipimages.ship1 { class Ship1Images {
[Embed(source="0001.png")] public var img0001:Class;
[Embed(source="0002.png")] public var img0002:Class;
[Embed(source="0003.png")] public var img0003:Class;
} }
.
package shipimages.ship2 { class Ship2Images {
[Embed(source="0001.png")] public var img0001:Class;
[Embed(source="0002.png")] public var img0002:Class;
[Embed(source="0003.png")] public var img0003:Class;
} }
But as I said, this is only beneficial in a small case scenarios but it does mean everything is more sub divided and if you were to make an Interface it could be easily done for factory pattern.
If you have lots of assets, the best way is to leave them as external files and use Loader to load them.
That way you can display a progress bar and, as you said, it also makes it easier to manage your assets.
Do you want to have the objects readily available within the same swf or do you want to load them externally. Would be the first question, that comes to my mind.
If you want to embedd images inside the swf : Add them all in an fla, create a swc from it and use them in your project. When you want to change something, change the fla. Regenerate the swc. Recompile.
If you want the images to be loaded on runtime, use UrlLoader, personally I prefer using LoaderMax, which is part of the greensock package. It gives you more options to work with loading. Here is an example to help you out : http://www.greensock.com/loadermax-tips/