A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29

Thread: A problem in auto scaling

  1. #21
    Senior Member
    Join Date
    May 2016
    Posts
    451
    total mc =30
    for example
    if i have 20 images only
    there are 10 mc empty ( not loaded image)

    if i have image named (unknown.jpg)

    1- how to the 10 mc empty load unknown.jpg
    2- how to add button press event for all mc

  2. #22
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hello,

    At the onFrame(2) scripting section I added a mouse move event so at the start the scroller wont move by accident:
    PHP Code:
    var num:Number=0
    onMouseMove 
    = function() {//On mouse move event.
    num++//Increase num value.
    }

    onEnterFrame=function(){//At the onEnterFrame event.
    if(num<5){//If the mouse has been moved enough times, the scroller will be useable.
    }else{
    if(
    _root._ymouse<main.container._y+main.container._height&&_root._ymouse>main.container._y){
    if(
    _root._xmouse>Stage.width/2){
    mode_right="A"
    mode_left=null
    offset
    ++
    refreshOffset(false)
    }
    if(
    _root._xmouse<Stage.width/2){
    mode_right=null
    mode_left
    ="A"
    offset--
    refreshOffset(false)
    }
    }
    }

    At the _root.main.container2 scripting section:
    PHP Code:
    _root.main.container["mc"+(amount)].onPress=function(){//Check if a box is pressed.
    _root.main.container["mc"+(this._name.split("c")[1])]._alpha=15//Set alpha level of the box from container 1 & container 2 to alpha = 15.
    _root.main.container2["mc"+(this._name.split("c")[1])]._alpha=15
    }
    _root.main.container2["mc"+(amount)].onPress=function(){//Repeat the same proces as above.
    _root.main.container["mc"+(this._name.split("c")[1])]._alpha=15
    _root
    .main.container2["mc"+(this._name.split("c")[1])]._alpha=15

    At the _root.main.container2 scripting section:
    PHP Code:
    loader_listener.onLoadError = function() {//If an image fails to load, continue through the rest of the loads.
    if(amount<_root.squares_total){//If the amount loaded is less than the total amount to load.
    amount++//Increase amount for the next squares string name.
    picture_name++//Increase picture name for the url loader to select the next option.
    img_loader.loadClip(file_path+String(picture_name)+".png",_root.mc);//Load the next image.
    }
    }; 
    download v10 (swish)
    download v10 (as2)
    Last edited by AS3.0; 01-09-2023 at 07:57 PM.

  3. #23
    Senior Member
    Join Date
    May 2016
    Posts
    451
    can you use for loop statement in ( _root.main.container2) to load external images

    sometimes i use ( some functions) mc ? to mc ?

  4. #24
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hello, It loads external images, you need to modify the file path in _root.main.container2:
    PHP Code:
    var file_path:String="C:\\Users\\Desktop\\Desktop\\movie\\myfolderImages\\"//Change to your file path. 
    You can also adjust the speed in the onFrame(2) scripting section, I put it slow so that I can click the square:
    PHP Code:
    var offset:Number=0
    var saved_spacing:Number=0
    var squares_total:Number=30
    var squares_visible:Number=30
    var squares_spacing:Number=1.5
    var speed2:Number=200//Decrease number to increase scrolling speed.
    var error:Number=1

    download v11 (swish)



    Last edited by AS3.0; 01-11-2023 at 12:36 AM.

  5. #25
    Senior Member
    Join Date
    May 2016
    Posts
    451
    i know it works fine
    but i need for loop
    can you

  6. #26
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hello, I had to rewrite the program to work for the loop, so everything is attached from the library now.

    On lines 45 of the onFrame(2) scripting section, calling the function createScroller 3 times will produce 3 scrollers each with there own settings.
    PHP Code:
    createScroller(20,20,1,200);//Squares total, Squares in view, Spacing, Speed.
    createScroller(8,5,1.5,200);//Squares total, Squares in view, Spacing, Speed.
    createScroller(8,8,3,200);//Squares total, Squares in view, Spacing, Speed. 
    On lines 32 of the onFrame(2) scripting section the background is now attached from the library and uses the name _root.bg:
    PHP Code:
    _root.attachMovie("bg","bg",_root.root_depth++); 

    On lines 34 of the onFrame(2) scripting section this is how each scroller is created:
    PHP Code:
    function createScroller(a,b,c,d){
    createEmptyMovieClip("container"+amount_of_scrollers++,_root.root_depth++);//Create empty movieclip called container1, next time around it will be container3.
    createEmptyMovieClip("container"+amount_of_scrollers++, _root.root_depth++);//Create empty movieclip called container2, next time around it will be container4.
    scroller_profile[amount_of_scrollers-2]={offset:0,squares_total:a,squares_visible:b,squares_spacing:c,speed2:d,saved_spacing:0}//Each scroller has a profile that can be accessed as scroller_profile[number].offset etc...

    for(var i=0;i<scroller_profile[amount_of_scrollers-2].squares_total;i++){//Example useage of the scroller profile to reach squares total for the current scroller.
    _root["container"+(amount_of_scrollers-2)].attachMovie("square","mc"+i,_root["container"+(amount_of_scrollers-2)].getNextHighestDepth());
    _root["container"+(amount_of_scrollers-1)].attachMovie("square","mc"+i,_root["container"+(amount_of_scrollers-1)].getNextHighestDepth());
    }

    download v12 (swish)
    download v12 (as2)
    Last edited by AS3.0; 01-12-2023 at 01:05 PM.

  7. #27
    Senior Member
    Join Date
    May 2016
    Posts
    451
    thank you very much

  8. #28
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hello, I added unknown.png for url not found:

    PHP Code:
    loader_listener.onLoadError = function() {//On load error.
    if(amount<scroller_profile[1].squares_total){//If the amount to load is less than the amount of squares in the second scroller added.
    //amount++//Ignore increasing amount for error loads.
    //picture_name++//Ignore increasing picture name for error loads.
    img_loader.loadClip(file_path+"unknown.png",_root.mc);//Load unknown.png for error loads.

    }
    }; 
    download v13 (swish)
    download v13 (as2)

  9. #29
    Senior Member
    Join Date
    May 2016
    Posts
    451

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center