Subclassing Sprite with maintimeline MC's

wow, what a day. day 2 of learning AS3 by diving in the deep
end!
anyway...........
ok, so if i'm gonna make a display object class then i'm
gonna extend Sprite. cool, this much understood. the problem ihave
is that the project is for an arts organisation and some of the
artists there are gonna appreciate the work a lot more if they can
actually SEE what their proposed screens look like in the FLA
itself. to that end, i've inherited an FLA that has a bunch of mcs
- single frame containers essentially with the odd button /
textinput / image inside - that are to serve as the actual screen
furniture themselves
or, in short, i'm not creating the display objects
dynamically with AS3: they're already sitting there for me on the
stage.
so the question is: what's gonna be the best way of
incorporating these mcs into a class that extends Sprite? in my -
possibly naive, i have no idea (only been doing this for 2 days!!!)
- view these classes WOULD ACTUALLY BE these mcs. like i had some
container called 'screen1_mc' and that somehow became:
public class FirstScreen extends Sprite
so if i pass them in via the constructor, like:
var screen1:FirstScreen = new FirstScreen( screen1_mc )
thats not going to do it is it? then screen1_mc will simple
become a property of FirstScreen.as, not FirstScreen.as itself,
like:
public function FirstScreen ( firstScreen:Sprite )
_firstScreen = firstScreen;
etc..........
hmm............ hows this done then? :S
dub.

overnight silence eh?
you know what: f_ck it, i'm going to bosch it in as a
property of the class and leave it at that.
if anyone wants to suggest to me a better solution, please,
i'm all ears...............

Similar Messages

  • Custom shapes/sprites with code, where to start?

    Hello,
    I want to start building some prebuild shapes, like a star, cross, heart, and some more with code.
    Does anyone know if there is already something like this ? A library with custom sprites or shapes?
    And should i create these graphics extending the sprite or shape class? I read that shapes would
    be better for performance?
    Regards,
    Chris.

    thanks Kglad, i did some search on this topic, but could not find
    prebuild shapes in Flash. So when i want to set properties of a shape, then
    it is better to use a Sprite?
    var myShape:CustomArrow = new CustomArrow();
    myShape.color = 0xFF0000;
    myShape.arrowSize = 14;
    myShape.arrowlineWidth = 200;
    This is the idea of using dynamic Shapes.
    Regards,
    Chris.

  • Best method for animated bitmap sprites with GPU?

    I've been looking at how GPU Hardware Acceleration is achieved with cacheAsBitmap and cacheAsBitmapMatrix which I understand for static bitmap sprites (+rotation/scale) but I don't quite understand how this would be used to animate a sprite that had different animation frames.. in terms of what is done by the GPU and what is done by the CPU
    eg potential scenarios:
    1) cache sprite sheets to GPU. use copyPixels to blit the various sprites to a single canvas. In this case presumably the canvas would not be GPU accelerated because it is constantly changing every frame. Is there in fact any benefit of having the sprite sheet cached here? is the GPU actually used for the blit onto the CPU-rendered canvas?
    2) cache individual sprite bitmap(data) frames on the GPU. use object pooling for game character sprites and add them to stage on startup. Change the bitmap every frame dynamically,  for animated sprites, to one of the cached bitmapdata textures. is the GPU actually being used in this case to change the bitmap of the sprite? or is it forced to CPU processing again?
    The only scenario I currently know should be GPU accelerated is if I use a cached sprite that doesn't animate (other than rotating and scaling with the bitmap matrix).
    thanks for any advice
    J

    J, I believe (2) is how it is currently done. A better method is required! - basically the same question I have that you are helping me with . That link to 'Yeah, but is it Flash' in my post shows an example of exactly that method (individual BitmapData for each frame).
    Just for completeness I will add the one from my post (though unsure if it is even possible):
    (3) Single BitmapData sprite sheet cached to GPU. Each Bitmap that uses this sprite sheet can somehow specify the x,y,width,height of the frame within this sprite sheet to use.

  • Swap sprite with if/then

    Hi,
    How would I write a script that would when sprite clicked
    would swap sprite then when clicked on again would swap back to
    original sprite.
    This is the script I am doing - and not working. I am
    obviously a beginner but learning.
    on mouseUp
    if the memberNum of (clickOn) = 3 then
    memberNum = 4
    If the memberNum of (clickOn) = 4 then
    memberNum = 3
    end
    Thanks for the help.

    I suppose I should offer a bit of explanation, so that you
    can learn
    from it. First of all to be more accurate, you are not
    swapping a
    sprite. You are swapping the sprite's member property.
    There is no reason to use the clickOn, as the mouseUp event
    is received
    by the sprite, and he already knows who he is (in a manner of
    speaking).
    Also you are using 2 if/then statements, where an
    if/then/else makes
    more sense.
    You will want to avoid hard coding of things like a
    membernum. Why? Well
    suppose that you need this same "toggling" behavior on 10
    different
    sprites. With the hard coding, you will have to have 10
    different
    scripts, one for each sprite. They will all be identical,
    with the
    exception of the membernum. So one would have 3 & 4, the
    next 5 & 6, 7 &
    8, etc.
    What happens if you decide to move things around in your
    cast? You just
    broke those 10 scripts. What happens if you decide that you
    want to add
    something, like a "beep" sound when the image changes. Well
    now you have
    to add that new code to 10 scripts.
    One behavior can handle the job, so there is no good reason
    to not to do
    it with one. The key is in the declaring of your own sprite
    properties.
    In the code, I defined a property called "pOriginalMember".
    Notice that
    this gets set during the beginSprite event. Thus I can
    attaqch this
    behavior to any number of sprites. Each will automatically
    remember the
    member that it started with.
    The other property is "pSwapMember". This will hold a
    reference to the
    member which is to be used for the toggle. The property is
    declared in
    the getPropertyDescriptionList handler. You will want to read
    up on that
    as it is quite useful. The property has to be set using
    Director's
    property inspector, under the behavior tab, double clicking
    the
    behavior. A dialog box will appear and let you set the value
    of
    pSwapMember for a particular instance.
    This is how one behavior can be utilized over and over. It
    will also not
    be broken by rearranging the cast. You can update the script
    if needed,
    without having to do so in multiple behaviors. Taking this
    approach will
    save you lots of time and effort over the long run.
    There is

  • Subclass UIScrollView with Custom Class

    I want to use my custom class "ImageGridView" (subclass of UIScrollView) in Interface Builder.
    Here is what I have done:
    1) Dragged a UIScrollView onto my main view in IB.
    2) Changed the new UIScrollView Class Identity to "ImageGridView" which autocompleted so I thought it should work if it found it no prob.
    3) Placed an NSLog(@"HIT") in the init of the ImageGridView code.
    4) Also tried debugging break in the ImageGridView
    No luck....i can't get the custom class to instantiate .....no code is even run in that class.

    Don't forget that the class will be instantiated within Interface Builder and 'saved' within the NIB. At runtime it is unsaved with all of the initialised parameter values intact.
    Try using the 'viewDidLoad' (??I think this is the name - going by memory here) method which is called after the view has been restored from its saved state in the NIB.
    Susan

  • Hiding & Unhiding Sprite with Lingo?!

    Whats up guys; here's the situation.
    I have some videos that play; the problem is that it's
    unclear when each video is done playing. So the client wants me to
    flash the next button once the video in that section is done
    playing.
    So here's what I have; I set the visibility of the
    highlighted next button to 0 on the first frame. Then I detect the
    currentTime of the video and once it reaches the end I set the
    visibility to 1.
    Works perfectly, the video stops and the next button appears.
    The problem is that I can't "re-hide" the next button once the user
    starts the next video clip.
    I tried using the same function as I do in the first frame,
    but the next button just won't hide. Here's my Lingo:
    First Frame to hide the nextbutton:
    on exitFrame
    sprite("nextbuttonroll").visible = 0
    end
    Lingo to unhide the Next button once a video is done:
    on Exitframe
    if sprite("capitol").currentTime > 5000 then
    sprite("nextbuttonroll").visible = 1
    end if
    end
    Then 1 frame before the next video starts I just pasted that
    first line again:
    on exitFrame
    sprite("nextbuttonroll").visible = 0
    end
    And it just stays there. It seems like that second function
    is forever stored in memory and it never wants to re-hide the next
    button.
    Any ideas? Can I clear the memory using unLoadMember or
    something?

    Jeez...talk about a headache over nothing.
    The problem was that I was viewing it in Director (not the
    published projector) and for some reason buttons tend to stay in
    there roll0over state. (something about how Director does it's
    Window Focusing)
    Anyway, I published the file and it works perfectly.
    So the code above is legit if someone wants to use it.

  • Saving an array of sprite with filestream

    hi I am looking for a way to save an array of sprite on the user drive and then read this array...
    I saw method for saving text file. It quite simple... but it seems that saving an array is not very documented.
    Any help  tuto/ code wil be appriciated
    Thanks

    Hi so maybee it 's a better idea to convert spite to bitmapdata
    var mySprite:Sprite = new Sprite();
    var bData:BitmapData = new BitmapData(mySprite.width, mySprite.height, true);
    bData.draw(mySprite);
    var bmap:Bitmap = new Bitmap(bData);
    and then save the bitmapdata ?
    I will look at the bae 64 and join split method.

  • Subclassed EJB with RolesAllowed annotation not giving permission

    A servlet is calling a method of an EJB (name EJB B). EJB B is a sub class of EJB A which contains the method and is not overridden by EJB B.
    EJB A uses the annotation @RolesAllowed({"user","system","admin"})
    EJB B uses the annotation @RolesAllowed({"system"})
    When the call is made by the servlet the following error is produced:
    JBAS014134: EJB Invocation failed on component EJB B for method xxxx: javax.ejb.EJBAccessException: JBAS014502: Invocation on method: xxxx throws exception of bean: EJB B is not allowed
    If I replace the EJB A annotation with @PermitAll then the method is called without the permission problem.
    I am wondering why the 'system' role allowed in EJB A is ignored in the annotation and the exception is thrown.
    Is this a bug perhaps?

    Hi Jay Bhaiya,
    I am getting the correct output by following the below:
    1: Change the SecurityRolesImpl.java to provide the below role that can access the EJB method:
    *@RolesAllowed({"TestRole"})*
    2: Then build the service as normal using the same build.xml
    3: Do not depoly the EAR using ant and try to use the Admin Console to deploy the EAR.
    4: While deploying the application through the admin console choose the below option:
    Custom Roles: Use roles that are defined in the Administration Console; use policies that are defined in the deployment descriptor.
    5: Then create the client stubs using the build.xml
    6: Then go to the Admin Console.
    Security Realm >> my realm >> users and Groups >> create a user TestUser ( pass- TestUser).
    7: Then Click on the RolesAllowedEar under the depolyments tab.
    Click on Security >> Roles ..
    Create a New Role >>> TestRole.
    Click on the Role created (TestRole) >>> Add Condition >>>
    Within Add Condition >> select User >> NEXT >>>
    Enter TestUser >>> Click ADD .
    Click Save.
    Now try to access the Web Service using the client code.
    Thanks,
    Sandeep

  • Moving Sprite with arrow keys, simultaneous directions

    Hi everyone.
    I'm trying to create a small arcade style game, you control a
    small ship, shoot at incoming targets, try to dogde their shots,
    etc. I'm working on the ship's movement right now, using the arrow
    keys to control it. Getting it to move one direction at a time is
    easy, but sometimes I need to move it diagonally, otherwise I think
    gameplay will suffer considerably.
    I have tried several things but I never seem to be able to
    tell Flash that two keys are being pressed simultaneously. Can
    anyone tell me how I might achieve this?
    Thank you.

    This format should allow detection of multiple keys at once:
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
    function keyPressed(ev:KeyboardEvent):void {
    var pressedKey:uint = ev.keyCode;
    if(pressedKey == Keyboard.LEFT) {
    leftDown = true;
    if(pressedKey == Keyboard.RIGHT) {
    rightDown = true;
    if(pressedKey == Keyboard.UP) {
    upDown = true;
    if(pressedKey == Keyboard.DOWN) {
    downDown = true;
    ship.addEventListener(Event.EnterFrame, moveShip);
    }

  • What is wrong with as3

    this is not a question about 'how i do X'. is rather a 'discussion' (flame or whatever, but to defend or argue about aspects, not people) about 'what is wrong with as3' and what aspects whould be taken into consideration for updates. right now i am using as3, and since i paid for this license, i choose this tool over some alternatives and i am using it to do stuff for other people who pay me to do it, i think it can be helpful for all of us if some actions are started in the right direction. i have already posted about 'all people in adobe are dumbasses that do not know how to make a scripting tool and are messing up my work', but i was pissed at the time (i still am pissed) but i believe this is not the right aproach. instead, if this goes to the right people in adobe, we all may get something in the future, like better and easier todo apps and web presentations.
    pre: not only about the as3 specification, but COMPLY with the specification that you set. for example, some time ago there were problems with matrix transforms. this was corrected later with a patch. but this means it is not even doing what is is supposed to do
    1. scriptable masks and movement, sprites and child sprites: there is a sprite with a mask, the mask is a shape drawn via script, something like
    somemask=new shape();
    somemask.graphics.beginfill();
    (...etc)
    somesprite.mask=somemask;
    just like that. now add some child sprites to 'somesprite', and make 'somesprite' move, scale and rotate. there you will have something like a kaleidoscope, but not what you expected to do with your script. as the child sprites move in the parent mask, you will see that the child sprites appear or dissapear kind of randomly, and if the child sprites are textfields, it may be that the text is rendered outside the mask, or partially rendered outside the mask (as in only part of the text), rendered with the wrongf rotation or in the wrong place. some child sprites are clipped correctly, some dissapear totally when only a part should dissapear (clipped) etc.
    way around: have not tried it yet, but i have the impression that bitmaps have different criteria for clipping, so i am thinking of trying this: appli an empty filter (a filter with params so it does not have any effect on the sprite or in the textfield) so the sprite is rendered as bitmap before doing anything else with it. as i said, i have not done it yet, but it may be a way around this problem, to avoid all this inconsistency with clipping
    1-b. inconsistency between hierarchy and coordinates, specially masks: you apply a mask to a sprite, yet the sprite has a set of coordinates (so 'x' in the sprite means an x relative to its container), yet the mask applied to the very same sprite, as another reference as reference for coordinates (like the stage)
    2. painting via script: in any other languaje, in any other situation, something like:
    beginFill(params);
    (...stuff 1)
    endFill();
    beginFill(params);
    (...stuff 2)
    endFill();
    (...etc)
    means: render region of block 1, then render region of block 2 etc, and no matter what, it should be consistent, since there is noplace for ambiguity. if you read it, you may think what that means, even if you dont run it you may have an idea of the picture you want to draw, but not with as3. as3 somehow manages to screw something that simple, and mixes all the blocks, and somehow uses the boundaries of one block as boundaries for other block. is like all blocks are dumped into whatever, and then uses all lines defined into it as boundaries for a unique block. it changes all boundaries and generates inconsistency between what is shown and redraw regions of the resulting picture, like lines that go to the end of the screen and then dont go away in the next frames, even tough the beginfill endfill block should prevent it
    3. event flow: i dont know what was the policy behind as3 event flow design. it is in no way similar or an extension to previous event flow, neither with any event flow in any other plattform. i dont know how most people start with as3; in my case, i unpacked, installed and when i tried to do something with what i already knew i could not, so i started reading the as3 docs, and since is like 800 pages long, i just read the basics and the rest i would 'wing it'. in the part of the event flow, there was something about bubbling and stuff, it was not clear at all and when i tried to do what is was said in the documentation (like preventing events to 'bubble', as is called in the documentation), i could not see any effect but i could see it was a mess. flash is not the only thing out there to work with pictures or to work with mouse events, but is the only one that deals with things like 'target' and 'currentTarget'. my first experience on needing this was when i was dealing with my own event handlers (so the only thing that had control over mouse was the stage, and i would admin everything via script). there were events generated everywhere, the stage got events that were not genrated directly over the stage, but got there not with stage coordinates but the coordinates relative to the sprite that generated the event. so if i hover the mopuse over the stage, and the stage has some things on it how does it work? i get multiple event calls, like it was hovering multiple times over the stage in a single frame, but in each call with different coordinates? and what if i set all child sprites as mouseenabled=false or compare like 'if (event.target != event.currenttarget)', what if i move the mouse over a child, does it prevent the move mouse event at all? or does it filter only the event call with only stage coordinates? in my case, every time i move over another clip (with mouseenabled = true), the stage gets it as 'mouse up', even tough there was never a mouse release, what the hell? do even the people at adobe know how to handle events with their own tool when they require it? why does an event 'bubble' when i have not specifically tell it to do it? mi thought is that this event flow was very poorly conceived, and tough the intention may have been that there were different cases and it shopuld cover all cases, they actually introduced new problems that were not present in traditional ways to handle it, and it is neither the easier way to handle things, and this way, a very simple problem turns into a very ugly thing because it must handle things that were not neccesary to handle, or were implicit in other situations.
    4. legacy: since as3, all interaction is different, and if you want to do things in the new plattform, using the new features, what you already knew just goes to the garbage can. when a new tool arrives, it should be an extension to previous tools (which is a reason to update instead of just buying a new tool from a different vendor). if everything i had or knew just means nothing from now on, then i can not say 'i know flash script', and my previous knowledge gives me no advantage when aproaching the new version. as3 is a new aproach that requires doc reading and stuff, even if you knew something about previous as specifications or other oo languajes. if you decide to change things from now on, like the things mentioned in this post, instead of just throwing away everything the users alerady knew about the tool, do like in java releases, they mark some things as 'deprecated', they keep working as they should, give a warning, but also a message saying this feature is deprecated, we suggest you use this library instead.
    5. lack of previous functionality: if you 'update' something, it meand all previos functionality is still there (probably improved, but not with bugs if it was working fine), plus something else. now it seems backwards, there are some things that could be done in previous versions but not in this one, like 'duplicatemovieclip'
    6. inconsistency with scripting/programming paradigms: (ok, fancy work, but fits perfectly here): as3 proposed ways to handle things, but the people who designed it got 'too creative', and they did something that is not consistent neither with previous versions of as or with other languajes. the documentations is full of things like 'it looks like x languaje or languaje family, but instead of using XXX word, you must use YYY'. great, what is this? namespaces 'work like', but 'differently' for example from java, .net, .c. its got the idea that a namespace means a grouped functionality but there are rules about where should be placed the file (ok, java has this also, .net takes care of it automatically if all files are registered in the project), but what you got is a mess that 'if you know other languajes you got the general idea, but nonetheless, even if you knew this or previosu versions of as, you still have to read whatever we decided arbitrarily just to be different'. namespaces, event handling, vars definition which is not like previous scripting neither like fully typed languajes.. is just a mess.
    7. lack of scripting and graphics integration: unlike flash and adobe tools that just got on the graphics side leaving all the scripting integratuion apart, most tools from other vendors integrate very well interacton with what is on the screen. the script editor: very poor. autocompletion? a drop down list that does not heklp at all, appears in the wrong places, and when you need it to go, it does not go (so if i want to move away from the uncalled drop down list, i have to click somewhere else, making developement slowewr instead of helping, so the drop down list does not capture all events when i dont want to). in other ides you double click somewhere and it will go to the part of code relevant to that event or whatever. for example microsoft tools, ok i am antimicrosoft, and one of the reasons was that when windows 95 got to market proposing itself as the ONLY pc os you could use if you wanted to keep useing the apps you already had, it was a lousy product full of flaws but you had to keep using it because you had no choice. what is so different from what is happening with flash just now? yet the ide of c# is awesome, works very well and seems reliable.
    adobe people: not all user are designers that just make pretty pictures. if it is not intended for scripting then why is it there. and if there are corrections to be done, they should patch all versions, not only the last one. previous version users also paid for their versions.

    Well, there is no point in arguing.
    I personally believe AS3 does exactly what it promises to do within limits (read: reasonable limits) of ECMA type of language. And sometimes it doesn’t do what we expect it to for it cannot possibly emulate everyone’s thinking process. The task, I guess, is to learn to think in terms of AS3 – not to try to make AS3 think like us. No language covers all the grounds. And no, it is not Java - with no negative or positive connotation. It is what it is. Period. I just hope that AS5 will be more Java like.
    You are right about the fact that it is not necessary to know all the aspects of language in order to perform the majority of tasks. But it is paramount to have a clear idea about such fundamental concepts as display list model and events. For instance, depth swap has no meaning in terms of AS3 because display list object stacking is controlled automatically and there is no need for all these jumping through hoops one has to perform in order to control depth in AS2. There no more gaps in depths and one always know where to find things.
    Similarly, there is no point in having duplicateMovieClip method. More conventional OOP ways of object instantiation accomplishes just that and much more. Just because OOP object instantiation needs to be learned doesn’t mean past hacks have place in modern times. duplicateMovieClip is a horse carriage standing next to SUV. What one should choose to travel?
    Events are implemented to the tee in the context of ECMA specifications. I consider Events model as very solid, it works great (exactly as expected) and never failed me. True, it takes time to get used to it. But what doesn’t?
    By the way, speaking about events, contrary to believe in Adobe’s inconsideration to their following. Events are implemented with weakly reference set to false although it would be better to have it set to true. I think this is because there are smart and considerate people out there who knew how difficult it would be for programming novices to deal with lost listeners.
    I think AS3 is million times better than AS2. And one of the reasons it came out this way is that Adobe made a very brave and wise decision to break totally loose from AS2’s inherent crap. They have created a totally new and very solid language. If they had tried to make it backward compatible – it would be a huge screw up, similar to how our friends at Microsoft are prostituting VB and VBA – extremely irritating approach IMHO.
    Also, Flash legacy issues shouldn’t be overlooked. Flash did not start as a platform for programmers. Entire timeline concept in many ways is not compatible with the best OOP practices and advancements. I think for anyone who is used to writing classes the very fact of coding on timeline sounds awkward. It feels like a hack (and AS2 IS a pile of hacks) – the same things can be nicely packaged into classes and scale indefinitely. As such I wouldn’t expect Adobe to waste time on hacking timeline concept issues by making smarter editor. They have made a new one – FlexBuilder – instead. Serious programmers realize very soon that Flash IDE is not for developing industrial strength applications anyway. So, why bother with channeling great minds into polishing path to the dead end?
    I would like to state that all this is coming form a person who knew Flash when there was no AS at all. And I applaud every new generation of this wonderful tool.
    I believe Adobe does a great job making transition from timeline paradigm to total OOP venue as smooth as possible. And no, they don’t leave their devoted followers behind contrary to many claims. They are working on making developing Flash applications as easy as possible for people of all walks. Welcome Catalyst!
    Of course there is not enough information about AS3 capabilities and features. But, on the other hand, I don’t know any area of human kind activities that does.

  • Need urgent help with LayerManager (easy example)

    Im trying to get a scrolling effect by moving the view window.
    THE PROBLEM IS that if I move the view vindow the Sprite (spriteTest) is displayed at the new position AND still at the old position. I don't want it to be displayed on the old position. So if I move it a pixel every 5 ms I get a trail of the Sprite. Why does it happen??? (clueless)
    Here is the code...
    import javax.microedition.lcdui.game.GameCanvas;
    import javax.microedition.lcdui.game.LayerManager;
    import javax.microedition.lcdui.game.Sprite;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;
    public class Game extends GameCanvas implements Runnable
        private Thread t; //the thread running the game
        private Midlet midlet; //the midlet
        private int DISP_WIDTH; //the width of the display
        private int DISP_HEIGHT; //the height of the display
        private int xpositionView, ypositionView; //the x and y coordinates of the view window (used for scrolling)
        private LayerManager world; //the layermanager in which all sprites are added
        private Sprite spriteTest; //a Sprite with an image looking like a goomba from super mario
        /** Creates a new instance of Game */
        public Game(Midlet midlet)
           super(true);
           this.midlet = midlet;
           xpositionView = 1;
           ypositionView = 1;
           DISP_WIDTH = getWidth();
           DISP_HEIGHT = getHeight();
           world = new LayerManager();
           world.setViewWindow(xpositionView, ypositionView, DISP_WIDTH, DISP_HEIGHT);
           try
                spriteTest = new Sprite(Image.createImage("/images/goomba.png")); //creates the sprite containing an image (no frames only 1 picture)
           catch(Exception e)
               System.out.println("Couldn't load sprite image!");
           spriteTest.setPosition(190, 30); //sets the position of the sprite
           world.append(spriteTest);      //appends the sprite to the LayerManager
        /* The game loop */
        public void run()
            Graphics g = getGraphics();
            while(true)
                move();
                render(g);
                try
                    t.sleep(5); //sleeps for 5 ms
                catch (InterruptedException ie)
        /* Moves the view window to the right*/
        private void move()
            xpositionView = xpositionView + 1; //update position 1 pixel to the right
            world.setViewWindow(xpositionView, ypositionView, DISP_WIDTH, DISP_HEIGHT); //sets the view window to the new location
        /* Render the graphics. !!!!PROBLEM!!! */
        public void render(Graphics g)
            world.paint(g, 0, 0); //paints out the LayerManager
            flushGraphics();
       /* Starts the thread */
        public void start()
            t = new Thread(this);
            t.start();
    }

    I already do sleep the Thread 5 milliseconds.
    I've uploaded pictures and other to make you understand the problem:
    http://www.freewebs.com/scrolling/picture2.jpg
    Here is the entire project (its only 122 kb small) if you can help me I would love you forever :) When you run this you will understand the problem.
    http://www.freewebs.com/scrolling/ScrollingSimple.rar
    Im desperate for help :(

  • How to delete objects created with new

    Hello,
    I am having a problem creating a behavior or script to delete new sprites created in channels. I have a behavior script that creates new sprites using the following (simplified) script:
    First, a Beginsprite creates a gChannel_list and assigns a beginning gChannel value. pSprite is used to establish the sprite that in the mousedown is clickon.
    on Beginsprite me 
      gChannel_List =[]
      gChannel = 70
      pSprite = sprite(Spritenum)
    end
    In the mousedown the gChannel is incremented and the newly created channel is added to the gChannel_list.
    on Mousedown me
      gChannel = gChannel + 1
      theChannel = addat(gChannel_List,gChannel)
      themember = pSprite.member
      channel(gChannel).makeScriptedSprite(themember, point(80,160))
      sprite(gChannel).width = thememberW
      sprite(gChannel).height = thememberH
      sprite(gChannel).rotation = theMemberR
      sprite(gChannel).moveablesprite = 1
      sprite(gChannel).ink = 36
    etc
    After creation of several sprites based on the the gChannel, the following globals, for example, are returned.
    -- Global Variables --
    gChannel_List = [71,72,73,74]
    gChannel = 74
    My problem is that I am unable to delete these created gchannel sprites with a lingo command. Deleting them from the list, for example, using deletat(gChannel,1), does nothing to remove them from the stage (they do disappear from the list). And while I can display their attributes such as width [n=getat(gChannel_list, x); put sprite(n).width], nothing seems to relate to deleting these gchannel sprites.
    How is it done?
    Hope this is enough information. If not, please let me know. I can provide whatever you might need. Please help.
    Rod

    Sean,
    DUH! Didn't even know that a 'removeScriptedSprite()' command existed! Very logical. It works perfectly. Thanks again so very much.
    Rod

  • Random movement within an irregularly constrained sprite (EDITED)

    (NEW EDIT AT BOTTOM)
    So, basically, I'm making a little program that crudely simulates an ant colony. I have little tunnels the ant-sprites can travel down, as well as chambers, in an irregularly-shaped sprite.
    I am not the most advanced at Director, but at least I've figured some things out. I found code on an open-source website (openspark, actually) that allows for an object to be dragged inside an irregular shape that has a matte ink.
    It's all well and good that the ants can be dragged within this boundary, but is there any way to have them use a Random Movement and Rotation behavior that is confined by the same laws? Or is that impossible / extremely hard?
    By the way, I already have a middleman behavior I use to toggle between dragging and random movement, so that does not factor into my question. I just need to know how to alter the Random Movement behavior so that it abides by the same constraint rules as my dragging behavior, if possible.
    Here is the code I'm using for dragging. I made a couple edits from the original, but not much.
    Don't worry about the canJumpGaps function of this code, as I am using a touch screen and it will never be used.
    property spriteNum
    property canJumpGaps    
    -- set to TRUE on mouseDown if the shiftDown
    property pSprite
    -- this draggable sprite
    property pConstraintSprite
    -- sprite to which this sprite is constrained
    property pConstraintAlpha
    -- alpha channel image of constraining member
    property pOffset
    -- offset between this sprite's loc and the mouse
    property pCurrentLoc
    -- last known position of this draggable sprite with respect to the constraining sprite
    -- EVENT HANDLERS --
    on beginSprite(me)
      pSprite  = sprite(spriteNum)
      pConstraintSprite = sprite(1)
      -- We'll use the value of the alpha channel to detect holes in the sprite
      pConstraintAlpha  = pConstraintSprite.member.image.extractAlpha()
    end beginSprite
    on mouseDown(me)
      canJumpGaps = the shiftDown
      if not pCurrentLoc then
        -- The user has not yet dragged the sprite anywhere.  Find out its
        -- current position with respect to the constraint sprite.
        pCurrentLoc = pConstraintSprite.mapStageToMember(pSprite.loc)
        if not pCurrentLoc then
          -- The mouse is not over an opaque part of the constraint
          -- sprite.  It can't be dragged at all.
          exit
        end if
      end if
      -- Start dragging
    pOffset = pSprite.loc - the mouseLoc
    end mouseDown
    on exitFrame(me)
      if not pOffset then
        -- The user is not dragging the sprite
        exit
      end if
    if the mouseDown then
        me.mMoveSprite()
      else
        -- The user just released the mouse
       pOffset = 0
      end if
    end exitFrame
    -- PRIVATE METHOD --
    on mMoveSprite(me) ---------------------------------------------------
      -- SENT BY exitFrame()
      -- ACTION: Calculates how near to the current mouseLoc the draggable
      --         sprite can be dragged.
      tMouseLoc = the mouseLoc + pOffset
      -- Find where the mouse is with respect to the constraint member
    tImageLoc = pConstraintSprite.mapStageToMember(tMouseLoc)
      if voidP(tImageLoc) then
        -- The mouse is currently outside the constraint sprite.  Use a
        -- slower but more powerful method of determining the relative
        -- position.
        tLeft = pConstraintSprite.left
        tTop = pConstraintSprite.top
        tImageLoc = tMouseLoc-point(tLeft, tTop)
      else if canJumpGaps then
        -- Check if the mouse is over a non-white area of the constraint
        -- member
       tAlpha = pConstraintAlpha.getPixel(tImageLoc, #integer)
      end if
      if tAlpha then
        -- Let the mouse move to this spot
    else -- Can't jump gaps or the mouse is over a gap
        -- Find how near the dragged sprite can get
        tDelta  = pCurrentLoc - tImageLoc
        tDeltaH = tDelta.locH
        tDeltaV = tDelta.locV
        tSteps = max(abs(tDeltaH), abs(tDeltaV))
        if not tSteps then
          -- The mouse hasn't moved since the last exitFrame
          exit
        end if
        tSteps = integer(tSteps)
    if float(tSteps) <> 0 then
    tStep  = tDelta / float(tSteps)
    -- This makes sure I'm not dividing by zero.
    else
    tStep  = 1
    end if
    repeat while tSteps
    -- Move one pixel towards the mouse
    tSteps = tSteps - 1
    tLoc = tImageLoc + (tStep * tSteps)
    -- Test that we are still on an opaque area
    tAlpha = pConstraintAlpha.getPixel(tLoc, #integer)
    if not tAlpha then
    -- We've gone a step too far: move back to an opaque area
    tSteps = tSteps + 1
    exit repeat
    end if
    end repeat
    end if
    -- Update the absolute and relative positions of the draggable
    -- sprite.
    tAdjust     = tSteps * tStep
    pCurrentLoc = tImageLoc + tAdjust -- relative to constrain sprite
    tMouseLoc   = tMouseLoc + tAdjust -- relative to the stage
    -- Move the sprite
    pSprite.loc = tMouseLoc
    end mMoveSprite
    Thank you SO incredibly much to anyone who can help. This is for a senior project of mine in undergrad, and I really appreciate any help I can get. My resources on Director are limited, especially for odd issues like this.
    EDIT:
    So I found out that a way to do collision detection in Director is by using getPixel().
    I found this protected dcr file that is a perfect example of the way in which I want my ant objects to interact with walls:
    http://xfiles.funnygarbage.com/~colinholgate/dcr/irregular.dcr
    I've been trying to build a getPixel() collision detection mechanism for hours but have been unsuccessful.
    Basically, what I want the behavior to do is... get the pixel color of the tunnel sprite (sprite 2) at the center of the ant sprite. If the pixel color is white (the transparent background color surrounding the tunnel shape), I want to tell the Random Movement and Direction behavior this:
    pSprite.pPath = VOID
    sendSprite(pSprite, #mNewPath)
    pSprite.pRotate = VOID
    sendSprite(pSprite, #mNewRotation)
    This tells the Random Movement behavior to stop moving and determine a new path. The behavior should probably also offset the center of the sprite by a couple pixels when this happens so it is no longer over an opaque area and the Random Movement behavior won't get stuck.
    Will this work? If not, could anyone help me in building a collision detection behavior based on getPixel? This doesn't seem like it'd be all that difficult - at least in theory.

    Hi Roberto,
    I had an experience, which defies most common sense about data modeling. Moving from a cube to a ODS and then back on to a cube to introduce delta on a BPS delta application. It is a long sad disappointing store. But I had 24 keys (I know 16 is the max, I combined 6 keys into a single filed also had the same fileds in the data fileds, use these combination keys to deal with 16 key max limitation and adjusted during transformation.
    It did work, but later gave up due to some other functional issues and we realized it is a bad experiement due to everyones data understanding.
    I am saying is 16 key limitation is an issue, you can overcome with combining couple of fileds into a single filed in the start routine, map it and reuse it later.
    Hope this gives you some ideas.
    Goodluck,
    Alex (Arthur Samson)

  • Drawing with an effect other than Alpha Transparency and XOR

    Hello,
    I'm looking for a way to draw images (Or anything else for that matter) with simple effects other than the Alpha and XOR effects, such as Multiply, Subtract and Bitwise AND. I've realized it has something to do with the setComposite function, but I haven't figured out how to get further from there, and the documentation didn't seem very clear. This is my first time using Java fro anything graphical; most of my projects are done in PHP and C++.
    Could anyone help me with this, perhaps with an example?
    Thank you very much!

    I'm using Graphics2D. I have one big BufferedImage and other smaller once which I use as sprites. I'm rendering the sprites to the big buffer using drawImage. I need an efficient way to render some of the sprites with an ink effect such as subtract. I know it's possible to do it with a XOR effect by placing setXORMode(c1) before the drawImage function.

  • Sprite.graphics performance issue...

    Hello,
    I have been working on a pretty big project in flash. To
    start with, I designed my components in the authoring tool (mostly
    because I did not have an idea on how I wanted them to look). Once
    I got my story straight, I put everything together and I had a good
    look at my application. It was great. It was moving so fast that I
    couldn't believe it was flash...
    Then, I started replacing the pre-drawn components with
    Sprites and Shapes drawn in AS3 via Sprite/Shape.graphics and
    adding them as child with Sprite.addChild.
    I absolutely DID NOT change anything else.
    By the time I was finished, I noticed that my great
    performance was not there anymore... For example: I have a
    scrolling feature (when I click a sprite a few other sprites move
    up a few lines). It used to be instantaneous. Now there is a delay
    of about 1 second or more between the release of the mouse button
    and the actual scrolling. (Also, I have the previous version of the
    project and I can clearly see the time difference. So I am not
    imagining things :)).
    I have backtracked my work several times and there is no "one
    thing" that causes this... it just ads up as I convert from
    pre-drawn components to dynamically drawn ones.
    Also, I should mention that all my pre-drawn components were
    sprites with "Instance Names" (not shapes with no name).
    So, my question is: is there a performance difference between
    using Sprites pre-drawn in the authoring tool versus Sprites
    created in AS3?
    Appreciate all the help. Thank you.
    Tony
    PS: I can not go back to pre-drawn components because that
    will take away from the flexibility of the application.

    These instructions must be carried out as an administrator, if you have more than one account.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left.
    Copy the text on the line below:
    smcHandleInterruptEvent
    and paste it in the Filter text field. You may see some messages like this:
    SMC::smcHandleInterruptEvent WARNING status=0x0 (0x40 not set) notif=0x0
    The timestamps of those messages (if any) indicate the times, since the log was last cleared, when the processor was being throttled because of high temperature.

Maybe you are looking for